So I imagine this is correct:
$entity = $this->em->getReference($this->entity, $idUser);
$ctg = $this->em->getReference($this->entityCategory, $value);
$ctg->setUsers($entity);
$this->em->persist($ctg);
$this->em->flush();
but get the error:
Catchable fatal error: Argument 1 passed to
Doctrine\Common\Collections\ArrayCollection::__construct() must be of the
type array, object given, called in
C:\RDM\rede-market-1\Rede-Market-0\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php
on line 547 and defined in
C:\RDM\rede-market-1\Rede-Market-0\vendor\doctrine\collections\lib\Doctrine\Common\Collections\ArrayCollection.php
on line *47*
Em sexta-feira, 30 de maio de 2014 09h21min17s UTC-3, Jàπ (Jasper N.
Brouwer) escreveu:
>
> When defining a ManyToMany association between 2 entities, you do _not_
> need to create an entity for the join-table.
>
> In fact, you should treat the association as if there is no join-table.
> Doctrine will manage this for you.
>
> When using Doctrine, remember that you are working with PHP objects (not
> database rows). And PHP is perfectly capable of linking objects without
> using something like a join-object ;)
>
>
> PS: The join-table that Doctrine will create for you (if you use `doctrine
> orm:schema-tool:create`) will only contain 2 columns (`ctg_id` and `id`)
> which will form a composite primary key.
>
> --
> Jasper N. Brouwer
> (@jaspernbrouwer)
>
>
> On 30 May 2014 at 10:19:28, João Carlos Santa Ana ([email protected]
> <javascript:>) wrote:
> > *I have the following questions:*
> >
> > class User {
> >
> > /**
> > * @ORM\Column(name="id", type="integer", nullable=false)
> > * @ORM\Id
> > * @ORM\GeneratedValue(strategy="IDENTITY")
> > */
> > private $id;
> > ...
> >
> >
> > class Category {
> >
> > /**
> > * @var integer
> > *
> > * @ORM\Column(name="ctg_id", type="integer", nullable=false)
> > * @ORM\Id
> > * @ORM\GeneratedValue(strategy="IDENTITY")
> > */
> > private $ctgId;
> >
> >
> > /**
> > * @var \Doctrine\Common\Collections\Collection
> > *
> > * @ORM\ManyToMany(targetEntity="User", inversedBy="categorys")
> > * @ORM\JoinTable(name="category_user",
> > * joinColumns={
> > * @ORM\JoinColumn(name="category_id",
> > referencedColumnName="ctg_id")
> > * },
> > * inverseJoinColumns={
> > * @ORM\JoinColumn(name="id", referencedColumnName="id")
> > * }
> > * )
> > */
> > private $users;
> >
> >
> > *How to insert into table CartegoryUser for this Entity*
> >
> > *Do I have to create CategoryUser or no*
> > /**
> > * CategoryUser
> > *
> > * @ORM\Table(name="category_user")
> > * @ORM\Entity
> > *
> @ORM\Entity(repositoryClass="Application\Entity\CategoryUserRepository")
> > */
> > class CategoryUser {
> >
> > /**
> > * @ORM\Column(name="ctg_user_id", type="integer", nullable=false)
> > * @ORM\Id
> > * @ORM\GeneratedValue(strategy="IDENTITY")
> > */
> > private $ctgUser;
> >
> > /**
> > * @var integer
> > *
> > * @ORM\Column(name="Categoria_id", type="integer", nullable=false)
> > * @ORM\Id
> > * @ORM\GeneratedValue(strategy="NONE")
> > */
> > private $categoryId;
> >
> > /**
> > * @var integer
> > *
> > * @ORM\Column(name="User_id", type="integer", nullable=false)
> > * @ORM\Id
> > * @ORM\GeneratedValue(strategy="NONE")
> > */
> > private $userId;
> >
> > Else yes i have create autoIncrement too, else i try by:
> > vendor/doctrine/doctrine-module/bin/doctrine-module
> orm:schema-tool:update
> > --force
> >
> > Get error: [Doctrine\DBAL\Schema\SchemaException]
> > The table with name 'rede-market.category_user' already exists.
> >
> > what better way to work.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.