I'm using doctrine to generate the entities from database in command line
doctrine orm:convert-mapping --force --from-database annotation ./Api/Entity
The php class is created correctly but when i try to use the repository to load the entity from the database
$decompte=$entityManager->getRepository(Decompte::class)->find(31);
I'm getting this exception
Class "entity\Decompte" is not a valid entity or mapped super class.
and please find above the entire code of the class entity\Decompte
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* Decompte
*
* #ORM\Table(name="decompte", indexes={#ORM\Index(name="N°D", columns={"ID"})})
* #ORM\Entity
*/
class Decompte
{
/**
* #var int
*
* #ORM\Column(name="ID", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var int|null
*
* #ORM\Column(name="NPRIXD", type="integer", nullable=true)
*/
private $nprixd;
/**
* #var string|null
*
* #ORM\Column(name="DESIGNATIOND", type="string", length=43, nullable=true)
*/
private $designationd;
/**
* #var string|null
*
* #ORM\Column(name="UNITED", type="string", length=2, nullable=true)
*/
private $united;
/**
* #var int|null
*
* #ORM\Column(name="QTED", type="integer", nullable=true)
*/
private $qted;
/**
* #var int|null
*
* #ORM\Column(name="PRIXHTD", type="integer", nullable=true)
*/
private $prixhtd;
/**
* #var string|null
*
* #ORM\Column(name="DECOMPTED", type="string", length=2, nullable=true)
*/
private $decompted;
/**
* #var int|null
*
* #ORM\Column(name="TOTALD", type="integer", nullable=true)
*/
private $totald;
/**
* #var string|null
*
* #ORM\Column(name="QMARCHE", type="string", length=11, nullable=true)
*/
private $qmarche;
/**
* #var string|null
*
* #ORM\Column(name="QDECOMPTE", type="string", length=5, nullable=true)
*/
private $qdecompte;
/**
* #var int|null
*
* #ORM\Column(name="SMARCHE", type="integer", nullable=true)
*/
private $smarche;
/**
* #var string|null
*
* #ORM\Column(name="SDECOMPTE", type="string", length=6, nullable=true)
*/
private $sdecompte;
/**
* #var int|null
*
* #ORM\Column(name="NDMR", type="integer", nullable=true)
*/
private $ndmr;
/**
* #var string|null
*
* #ORM\Column(name="RESTE", type="string", length=11, nullable=true)
*/
private $reste;
/**
* #var string|null
*
* #ORM\Column(name="RESTEF", type="string", length=11, nullable=true)
*/
private $restef;
}
when trying to debug this issue, i found out that the Annotation Driver reader's cache is empty
i've added somme "echo" in the AnnotationDriver::loadMetaDataForClass
echo 'allClassName'.$this->getAllClassNames();
echo 'allPaths'.$this->getPaths();
returns an empty array
$classAnnotations = $this->reader->getClassAnnotations($class);
is also empty
thank you very much for you help
I have a Forum Entity that may contain sub forums which will be of the same class(Forum) . i am having trouble with establishing this relation .
the code below is what i have tried so far in my Forum class
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=5000, nullable=false)
*/
private $description;
/**
* #ORM\Column(type="string")
*
* #Assert\NotBlank(message="Please, upload the forum wallpaper as a PNG file.")
* #Assert\File(mimeTypes={ "image/png" })
*/
private $wallpaper;
/**
* #var \DateTime
*
* #ORM\Column(name="added_date", type="datetime", nullable=false)
*/
private $addedDate;
/**
* #var array
*
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\User", cascade={"remove"})
*/
private $moderators;
/**
* #var Forum[]
* #ORM\OneToMany(targetEntity="Forum", mappedBy="id", cascade={"all"}, orphanRemoval=true)
*/
private $subForums;
/**
* #var \AppBundle\Entity\User
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $userId;
the problem after updating the database scheme i didnt end up with any table linkin forums and subforums so i am confused how can i add a sub forum to an exsiting forum later on . Any help is much appriciated
I believe what you are looking for is a One-To-Many self-referencing mapping
So change your $subForums like so:
/**
* #var Forum[]
* #ORM\OneToMany(targetEntity="Forum", mappedBy="parentForum", cascade={"all"}, orphanRemoval=true)
*/
private $subForums;
and add $parentForum, like so:
/**
* #ManyToOne(targetEntity="Forum", inversedBy="subForums")
* #JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parentForum;
I'm going to working in a Admin Backend to a WebPage with Symfony 2.2.8 and Javier Eguiluz's EasyAdminBundle 1.16.12 (last version). I installed the bundle following the instructions in GitHub page, and I have also created a couple of test entities (Users and Engagementes).
Well, my trouble is that the text type in the edit template not working, they are empty and without label, otherwise the entity can be edited correctly.
User:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* #ORM\Table(name="User")
* #ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*/
class User
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=true)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="surname", type="string", length=255, nullable=true)
*/
private $surname;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=50, unique=true)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255, unique=true)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* #var string
*
* #ORM\Column(name="role", type="string", length=50)
*/
private $role;
// getter and setter [...]
Engagement:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Engagement
*
* #ORM\Table(name="Engagement")
* #ORM\Entity(repositoryClass="AppBundle\Repository\EngagementRepository")
*/
class Engagement
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="code", type="string", length=20, unique=true)
*/
private $code;
/**
* #var string
*
* #ORM\Column(name="owner", type="string", length=255)
*/
private $owner;
/**
* #var int
*
* #ORM\Column(name="phone", type="integer", nullable=true)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="incident", type="string", length=255)
*/
private $incident;
/**
* #var string
*
* #ORM\Column(name="brand", type="string", length=50, nullable=true)
*/
private $brand;
/**
* #var string
*
* #ORM\Column(name="model", type="string", length=255, nullable=true)
*/
private $model;
/**
* #var string
*
* #ORM\Column(name="repairer", type="string", length=255, nullable=true)
*/
private $repairer;
/**
* #var float
*
* #ORM\Column(name="cost", type="float", nullable=true)
*/
private $cost;
/**
* #var float
*
* #ORM\Column(name="advance", type="float", nullable=true)
*/
private $advance;
/**
* #var \DateTime
*
* #ORM\Column(name="start_date", type="datetime")
*/
private $startDate;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=50)
*/
private $status;
/**
* #var string
*
* #ORM\Column(name="comment", type="string", length=255, nullable=true)
*/
private $comment;
// setters and getters [...]
Config.yml:
# [...]
easy_admin:
entities:
- AppBundle\Entity\User
- AppBundle\Entity\Engagement
And I get it with EasyAdminBundle:
P.S.: I'm sorry if I made mistakes, English is not my native language.
I want to create model which will have table users with reference to table CustomFieldValue nad table CustomField with reference to CustomFieldValue too. CustomFieldValue will have only id, value and two columns, one from users and second from CustomField. I want to have functionality like a dynamic adding a new fields in registration form. Is this good idea? If yes, please help me with this model, because it doesn't work:
User:
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* #ORM\Column(type="string", length=64)
*/
private $password;
/**
* #ORM\ManyToMany(targetEntity="Role", inversedBy="users",cascade={"persist"})
*
*/
private $roles;
/**
* #ORM\Column(type="string", length=60, unique=true)
*/
private $email;
/**
* #ORM\Column(type="string", length=60)
*/
private $sex;
/**
* #ORM\ManyToMany(targetEntity="Region", inversedBy="users")
* #ORM\JoinColumn(name="region", referencedColumnName="id")
*/
private $region;
/**
* #ORM\ManyToMany(targetEntity="Type", inversedBy="users")
* #ORM\JoinColumn(name="type", referencedColumnName="id")
*/
private $type;
/**
* #ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue",inversedBy="id")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $customValues;
CustomFieldValue:
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="value", type="string", length=255)
*/
private $value;
/**
*ORM\OneToMany(targetEntity="User", mapped-by="id")
*#ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
*#ORM\OneToMany(targetEntity="CustomField", mapped-by="id" )
*#ORM\JoinColumn(name="field_id", referencedColumnName="id")
*/
private $field;
CustomField:
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="type", type="string", length=255)
*/
private $type;
/**
* #var boolean
*
* #ORM\Column(name="required", type="boolean")
*/
private $required;
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="id")
* #ORM\JoinColumn(name="customfield_id", referencedColumnName="id")
*/
private $customValues;
Your mapping is a little off:
User Entity Should Be:
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="user")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $customValues;
CustomFieldValue Should Be:
/**
*ORM\OneToMany(targetEntity="User", mappedBy="customValues")
*/
private $user;
/**
*#ORM\OneToMany(targetEntity="CustomField", mappedBy="customValues" )
*/
private $field;
CustomField should be:
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="field")
* #ORM\JoinColumn(name="customfield_id", referencedColumnName="id")
*/
private $customValues;
You dont need the join columns when you are calling the mappedBy this already tells doctrine to look for the join column declaration on that field. For the mappedBy and inversedBy fields these are the fields that link the 2 together NOT the actual join column name.
I'm trying to write one form for submitting against MySQL DB, but I can't get it working, I've tried a lot of things (separate forms, create an ->add('foo', new foo()) to a field, and trying to parse plain SQL with a normal HTML form is my only solution, which is obviously not the best.
This is my DB structure:
![enter image description here][1]
As you can see I need to insert the comments textarea to ticketcomments among the user who wrote it, etc.
On crmentity the description field.
Then on ticketcf the fields that I need to submit from form, are this (because you wont know if I don't tell you because of the field names):
tcf.cf594 AS Type,
tcf.cf675 AS Suscription,
tcf.cf770 AS ID_PRODUCT,
tcf.cf746 AS NotificationDate,
tcf.cf747 AS ResponseDate,
tcf.cf748 AS ResolutionDate,
And, of course, every table needs to have the same ticketid id for the submitted form, so we can retrieve it with one simple query.
It will be easy to do with plain SQL instead of using DQL and Symfony2 forms, but is not a good way to do it.
EDIT
This is my new created entity Ticket.php, which has relations to the tables above... if someone could check it out and tell me if it's okay...
ticket.php
<?php
namespace WbsGo\clientsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VtigerTicketcomments
*
* #ORM\Table(name="vtiger_troubletickets")
* #ORM\Entity(repositoryClass="WbsGo\clientsBundle\Entity\TicketsRepository")
*/
class Tickets
{
/**
* #var \WbsGo\clientsBundle\Entity\VtigerCrmentity
*
* #ORM\OneToOne(targetEntity="WbsGo\clientsBundle\Entity\VtigerCrmentity")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ticketid", referencedColumnName="crmid", unique=true)
* })
* #ORM\Id
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="ticket_no", type="string", length=100, nullable=false)
*
*/
private $ticketNo;
/**
* #var string
*
* #ORM\Column(name="groupname", type="string", length=100, nullable=true)
*/
private $groupName;
/**
* #ORM\ManyToOne(targetEntity="VtigerContactdetails")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="parent_id", referencedColumnName="contactid", unique=true)
* })
*/
private $parentId;
/**
* #ORM\ManyToOne(targetEntity="VtigerAssets")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="product_id", referencedColumnName="assetsid", unique=true)
* })
*/
private $productId;
/**
* #var string
*
* #ORM\Column(name="priority", type="string", length=100, nullable=true)
*/
private $priority;
/**
* #var string
*
* #ORM\Column(name="severity", type="string", length=100, nullable=true)
*/
private $severity;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=100, nullable=true)
*/
private $status;
/**
* #var string
*
* #ORM\Column(name="category", type="string", length=100, nullable=true)
*/
private $category;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255, nullable=true)
*/
private $title;
/**
* #var text
*
* #ORM\Column(name="solution", type="text", nullable=true)
*/
private $solution;
/**
* #var text
*
* #ORM\Column(name="update_log", type="text", nullable=true)
*/
private $updateLog;
/**
* #var integer
*
* #ORM\Column(name="version_id", type="integer", nullable=true)
*/
private $versionId;
/**
* #var string
*
* #ORM\Column(name="hours", type="string", length=255, nullable=true)
*/
private $hours;
/**
* #var string
*
* #ORM\Column(name="days", type="string", length=255, nullable=true)
*/
private $days;
/**
* #var integer
*
* #ORM\Column(name="from_portal", type="integer", nullable=true)
*/
private $fromPortal;
/**
* #ORM\OneToMany(targetEntity="VtigerTicketcomments", mappedBy="ticketid")
*
*/
protected $comments;
/**
* #ORM\OneToOne(targetEntity="VtigerTicketcf", mappedBy="id")
*/
protected $ticketcf;
/**
* #ORM\OneToOne(targetEntity="VtigerCrmentity", mappedBy="crmid")
*/
protected $crmtable;
}
VtigerTicketcf.php
<?php
namespace WbsGo\clientsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VtigerTicketcf
*
* #ORM\Table(name="vtiger_ticketcf")
* #ORM\Entity
*/
class VtigerTicketcf
{
/**
* #var string
*
* #ORM\Column(name="cf_546", type="string", length=255, nullable=true)
*/
private $cf546;
/**
* #var string
*
* #ORM\Column(name="cf_556", type="string", length=255, nullable=true)
*/
private $cf556;
/**
* #var string
*
* #ORM\Column(name="cf_589", type="string", length=3, nullable=true)
*/
private $cf589;
/**
* #var string
*
* #ORM\Column(name="cf_590", type="string", length=3, nullable=true)
*/
private $cf590;
/**
* #var string
*
* #ORM\Column(name="cf_592", type="string", length=100, nullable=true)
*/
private $cf592;
/**
* #var string
*
* #ORM\Column(name="cf_593", type="string", length=255, nullable=true)
*/
private $cf593;
/**
* #var string
*
* #ORM\Column(name="cf_594", type="string", length=255, nullable=true)
*/
private $cf594;
/**
* #var string
*
* #ORM\Column(name="cf_675", type="string", length=50, nullable=true)
*/
private $cf675;
/**
* #var float
*
* #ORM\Column(name="cf_689", type="decimal", nullable=true)
*/
private $cf689;
/**
* #var float
*
* #ORM\Column(name="cf_690", type="decimal", nullable=true)
*/
private $cf690;
/**
* #var float
*
* #ORM\Column(name="cf_691", type="decimal", nullable=true)
*/
private $cf691;
/**
* #var float
*
* #ORM\Column(name="cf_693", type="decimal", nullable=true)
*/
private $cf693;
/**
* #var string
*
* #ORM\Column(name="cf_746", type="string", length=50, nullable=true)
*/
private $cf746;
/**
* #var string
*
* #ORM\Column(name="cf_747", type="string", length=50, nullable=true)
*/
private $cf747;
/**
* #var string
*
* #ORM\Column(name="cf_748", type="string", length=50, nullable=true)
*/
private $cf748;
/**
* #var string
*
* #ORM\Column(name="cf_761", type="string", length=255, nullable=true)
*/
private $cf761;
/**
* #var string
*
* #ORM\Column(name="cf_763", type="string", length=255, nullable=true)
*/
private $cf763;
/**
* #var string
*
* #ORM\Column(name="cf_764", type="string", length=255, nullable=true)
*/
private $cf764;
/**
* #var string
*
* #ORM\Column(name="cf_765", type="string", length=255, nullable=true)
*/
private $cf765;
/**
* #var string
*
* #ORM\Column(name="cf_770", type="string", length=50, nullable=true)
*/
private $cf770;
/**
* #var \WbsGo\clientsBundle\Entity\Tickets
* #ORM\Id
* #ORM\OneToOne(targetEntity="WbsGo\clientsBundle\Entity\Tickets")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ticketid", referencedColumnName="ticketid", unique=true)
* })
*
*/
private $id;
}
VtigerTicketcomments.php
<?php
namespace WbsGo\clientsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VtigerTicketcomments
*
* #ORM\Table(name="vtiger_ticketcomments")
* #ORM\Entity
*/
class VtigerTicketcomments
{
/**
* #var string
*
* #ORM\Column(name="comments", type="text", nullable=true)
*/
private $comments;
/**
* #var integer
*
* #ORM\Column(name="ownerid", type="integer", nullable=false)
*/
private $ownerid;
/**
* #var string
*
* #ORM\Column(name="ownertype", type="string", length=10, nullable=true)
*/
private $ownertype;
/**
* #var \DateTime
*
* #ORM\Column(name="createdtime", type="datetime", nullable=false)
*/
private $createdtime;
/**
* #var integer
*
* #ORM\Column(name="commentid", type="integer")
* #ORM\Id
*/
private $id;
/**
* #var \WbsGo\clientsBundle\Entity\Tickets
* #ORM\OneToOne(targetEntity="WbsGo\clientsBundle\Entity\Tickets")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="ticketid", referencedColumnName="ticketid", unique=true)
* })
*
*/
private $ticketid;
}
VtigerCrmentity.php
<?php
namespace WbsGo\clientsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VtigerCrmentity
*
* #ORM\Table(name="vtiger_crmentity")
* #ORM\Entity
*/
class VtigerCrmentity
{
/**
* #var integer
*
* #ORM\Column(name="smcreatorid", type="integer", nullable=false)
*/
private $smcreatorid;
/**
* #var integer
*
* #ORM\Column(name="smownerid", type="integer", nullable=false)
*/
private $smownerid;
/**
* #var integer
*
* #ORM\Column(name="modifiedby", type="integer", nullable=false)
*/
private $modifiedby;
/**
* #var string
*
* #ORM\Column(name="setype", type="string", length=30, nullable=false)
*/
private $setype;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(name="createdtime", type="datetime", nullable=false)
*/
private $createdtime;
/**
* #var \DateTime
*
* #ORM\Column(name="modifiedtime", type="datetime", nullable=false)
*/
private $modifiedtime;
/**
* #var \DateTime
*
* #ORM\Column(name="viewedtime", type="datetime", nullable=true)
*/
private $viewedtime;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=50, nullable=true)
*/
private $status;
/**
* #var integer
*
* #ORM\Column(name="version", type="integer", nullable=false)
*/
private $version;
/**
* #var integer
*
* #ORM\Column(name="presence", type="integer", nullable=true)
*/
private $presence;
/**
* #var integer
*
* #ORM\Column(name="deleted", type="integer", nullable=false)
*/
private $deleted;
/**
* #var integer
*
* #ORM\Column(name="crmid", type="integer")
* #ORM\Id
*/
private $crmid;
}
And this is my repository method...
public function findByIdAndCustomerId($id) {
$query = $this->getEntityManager()
->createQuery(
'
SELECT
IDENTITY(t.id) AS id,
t.ticketNo AS Ticket,
t.title AS Asunto,
t.status AS Estado,
t.updateLog AS LOG,
t.hours AS Horas,
t.solution AS Solucion,
t.priority AS Prioridad,
tcf.cf748 AS F_Reso,
tcf.cf747 AS F_Resp,
tcf.cf746 AS F_Noti,
tcf.cf770 AS IDPROD,
tcf.cf594 AS Tipo,
tcf.cf675 AS Suscripcion,
c.comments AS Comments,
CONCAT (CONCAT(s.firstname, \' \'), s.lastname) AS Contacto
FROM WbsGoclientsBundle:Tickets t
JOIN t.parentId s
JOIN t.ticketcf tcf
JOIN t.comments c
WHERE t.ticketNo = :ticketNo
')
->setParameter('ticketNo', $id)
;
try {
//return $query->getSingleResult();
return $query->getResult();
}
catch (\Doctrine\ORM\NoResultException $e)
{
return null;
}
}
I can retrieve an array of X ticket even if I just search by ONE ID, because if ID1 has 4comments, then I got 4 same tickets, one per comment... How can I make it only ONE ticket with comments => array(...) so I can iterate inside that comments array inside twig?
And also VtigerCrmentity.Description doesn't work either, it returns this error...
Notice: Undefined index: crmid in
/var/www/wbsgo/dev.wbsgo/vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php
line 826
I don't have getter and setter because I'm re-generating them again, if annotation are OK, the entities will update correctly with get/set and my forms will be able to submit using relationships, right?
You may embed a form that does represent an underlying entity field by setting mapped option to false, e.g.:
->add('comments', 'collection', array(
'type' => new VtigerTicketcommentsType(),
'mapped' => false
))
However, be careful when assigning form data, since $form->submit($data) will not set data to underlying collection of comment objects. You'll need to process them manually inside the controller. You may access the data that has been flagged as non-mapped using $form->getExtraData() after the data is submitted to the form.
If you'd like Symfony to automatically set data to comments, you'll need to construct a relationship between VtigerTroubletickets and VtigerTicketcomments entities, which, according to the question title, you don't have and try to avoid.
Edit:
A form type is bound to a given entity class. By default, each field you add to a form type must have an underlying property in a declared entity class (or getter/setter pair if property is not defined public). When you construct a form object from form type (OpenTicketType) and data (new VtigerTroubletickets()):
$form = $this->createForm(new OpenTicketType(), new VtigerTroubletickets());
the form get bounds with data present in the object you just created. The object does not have comments property, even more, the form itself knows the field is not mapped and it will not try to populate it from the object, so naturally the collection is rendered as empty, as no data about comments was passed.
To get past this, you may pass array of data instead of newly created object (note: the values may be empty, however comments array must have length > 0 - the comment has to exist, though without actual data).
[
"title" => "...",
"priority" => "...",
"solution" => "...",
"comments" => [
0 => [/* comment 0 data */],
1 => [/* comment 1 data */],
.......
]
]
This is the form creation. When the form is POST-ed, there is one additional step beside constructing the form. The request data has to be bound onto form, so you do $form->submit($request). Now the form AND underlying entity object will get populated with fresh data.
The $form->getExtraData() is simply a method for accessing the data that form holds and is not mapped to an underlying object - which comments field is, since we flagged it as such.
Alternatively to using getExtraData - extracting data from form manually - you may add a property comments to VtigerTroubletickets entity with getters/setters and not mark it as a db column. That way, you may remove the mapped => false option at form type, and form will automatically read/populate comments property.
Still, when persisting, these comments will not be considered for storing, so you'll have to handle them manually. Likewise, when fetching an object from database, the comments property would be empty, so prior to creating a form, you'd have to add some comments to an object, e.g.:
$tickets = new VtigerTroubletickets();
$tickets->setComments(....);
$form = $this->createForm(new OpenTicketType(), $tickets);
I think #usoban has taken you most of the way. Think of these as two long comments as opposed to answers.
It seems you have a ticket entity and a comment entity with a 1 to many relationship between them but you don't want to actually establish a formal relationship between them because the "DB is used by another platform"? What exactly does that mean. Are you sharing php code with another application? Are you using doctrine 2? With Doctrine 2 you can establish the relationship without changing the actual database.
You really should look at adding a getComments to your ticket entity. It will make your S2 life much easier.
This answer is built on what #usoban said about using an array but takes a slightly different approach.
// In the controller
$formData = array();
$formData['ticket'] = new Ticket(),
$formData['comments'] = array(new Comment(), new Comment());
$form = $this->createForm(new TicketCommentsType(), $formData);
$form->handleRequest($request);
if ($form->isValid())
{
$formData = $form->getData();
$ticket = $formData['ticket'];
$comments = $formData['comments'];
// Persist ticket
// Persist comments
TicketCommentsFormType simply brings the two different entities into one form.
class TicketCommentsFormType
public function buildForm(
$builder->add('ticket',new OpenTicketType());
$builder->add('comments','collection',array(
'type' => new VtigerTicketcommentsType()
With this approach there is no need to have any direct relation between Ticket and Comment.
I've found the way to do it, and the problems.
The relations are this:
crmentity.id > Main, this table has not relationships
troubleticket.ticketid > This one has relation with crmentity.id
ticketcf.ticketid > this one has relation with troubleticket.ticketid
So the order when you insert needs to be crmentity->troubleticket->ticketcf
But in Symfony2, when you make forms, you must create the last table element as the first form to be generated, so I'll post my code in case someone has the same problem as me.
http://pastebin.com/wLPyXvbj
:)