1

How do I map user_id field from user table to other tables. I am using Symfony2 and FOSUserBundle.

I have already tried by this way

My Contacts Entity

/*
 * @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
 protected $user;

My User Entity

/**
 * @ORM\OneToMany(targetEntity="Contacts", mappedBy="user")
 */
protected $contact;

I did

doctrine:schema:update --force 

Nothing to update - your database is already in sync with the current entity metadata.

There should be user_id field added to contacts table.

I tried adding cascade -- Ref Link

/**
 * @ORM\OneToMany(targetEntity="Contacts", mappedBy="user",cascade={"persist"})
 */
protected $contact;

But even that is not helping.

Community
  • 1
  • 1
chirag7jain
  • 1,485
  • 3
  • 26
  • 43

1 Answers1

2

In your contact entity

/*
 * @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
 protected $user;

It should be

/** 
 * @ORM\ManyToOne(targetEntity="User", inversedBy="contacts")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
 protected $user;

Missing extra star in doc block

FYI: DOC Block

Venu
  • 7,243
  • 4
  • 39
  • 54