symfony - User Object in a one-to-one relationship using primary key shared with foreign key -
iterations of question have been asked in past, presents unique challenges combines of issues in 1 larger problem.
i have entity(user) used user class in application, have entity (userextra), in one-to-one relationship user entity, userextra's id same user. foreign key same primary key.
when user object loaded (say $this->getuser()
or {{ app.user }}
, userextra data loaded through join. whole point of having 2 entities don't have load data @ once.
i tried defining custom userloaderinterface/userproviderinterface repository user, making sure refreshuser , loaduserbyusername load user data (i'd userextra data sit in proxy unless explicitly need it) when doctrine goes hydrate object, issues query load userextra data, thereby skipping proxy status.
is there way out of this?
there many solution issue:
1) change owning side , inverse side http://developer.happyr.com/choose-owning-side-in-onetoone-relation - don't think that's right db design perspective every time.
2) in functions find
, findall
, etc, inverse side in onetoone joined automatically (it's fetch eager). in dql, it's not working fetch eager , costs additional queries. possible solution every time join inverse entity
3) if alternative result format (i.e. getarrayresult()
) sufficient use-cases, avoid problem.
4) change inverse side onetomany - looks wrong, maybe temporary workaround.
5) force partial objects. no additional queries no lazy-loading: $query->sethint (query::hint_force_partial_load, true)
- seams me possible solution, not without price: partial objects little bit risky, because entity behavior not normal. example if not specify in ->select()
associations user can have error because object not full, not selected associations null
6) not mapping inverse bi-directional onetoone association , either use explicit service or more active record approach - https://github.com/doctrine/doctrine2/pull/970#issuecomment-38383961 - , looks doctrine closed issue
this question may : one 1 relation load
Comments
Post a Comment