Thursday, 15 January 2015

php - Doctrine2: OneToMany Annontation creates empty DB column -



php - Doctrine2: OneToMany Annontation creates empty DB column -

though i'm new doctrine2 , symfony2 know bit of zend , thought problem pretty basic, after trying few days now, guess might able help me:

i have 2 entities: accounts , members, 1 fellow member can have many accounts , 1 business relationship belongs member.

what created is:

class fellow member { /** * @orm\onetomany(targetentity="account", mappedby="members", cascade={"persist", "merge"}) */ private $account; public function __construct() { $this->account= new arraycollection(); } ... // next set doctrine: doctrine:generate:entities mma (my bundle) public function addaccount($account) { ... } public function removeaccount($account) { ... } }

and this:

class business relationship { /** * @orm\manytoone(targetentity="member") * @orm\joincolumn(name="member_id", referencedcolumnname="id", ondelete="cascade") */ protected $member; (with setter , getter) ... }

so expected next db table:

table account:

id, ..., member_id, ...

and table fellow member get:

id, ..., account_id, ...

why there account_id column? , although have methods column never filled anything... missing?

thanks! help appreciated

i think may have errors in variable names , 'mappedby' properties result of nomenclature not reflect explanation of relationship between member , account. if there onetomany relationship between two, intuitively write

class fellow member { /** * @orm\onetomany(targetentity="account", mappedby="member") */ private $accounts; public function __construct() { $this->accounts = new arraycollection(); } }

note new variable name accounts in plural , mappedby in singular member. account

class business relationship { /** * @manytoone(targetentity="member", inversedby="accounts") * @joincolumn(name="member_id", referencedcolumnname="id") */ protected $member; }

notice inversedby property tells collection on member side beingness referenced

php sql symfony2 doctrine2 innodb

No comments:

Post a Comment