Trac

Association Mapping

This page contains informations on the planned association/relation mapping capabilities of Doctrine 2.0.

Planned Additional Features

* Full composite key support

Discussions

Excerpt from a discussion with Jonathan:

[18:27]  <romanb> jwage: what exactly do you mean when you speak of "arbitrary dql parts in the relationship definition" ? currently i've only planned orderby and indexby. what else would you like to see?
[18:27]  <jwage> i'd like to see the ability to inject any dql parts
[18:27]  <romanb> how would that look like?
[18:30]  <jwage> for example say you have User.id == Phonenumber.user_id and Phonenumber.is_primary(boolean
[18:30]  <jwage> and you want a relationship on User named ActivePhonenumber
[18:31]  <jwage> so you could do hasOne('Phonenumber as PrimaryPhonenumber', array('local' => 'id', 'foreign' => 'user_id', 'dql' => array('where' => 'is_primary = 1')));
[18:32]  <romanb> wouldnt it  make more sense to put an active_phonenumer FK in the user table and do hasOne('Phonenumber as activePhonenumber' ... in addition to the hasMany ?
[18:32]  <jwage> sorry PrimaryPhonenumber not ActivePhonenumber
[18:32]  <romanb> or primary
[18:33]  <jwage> well, i guess you could solve that specific scenario that way
[18:33]  <jwage> but that was a super simple examle
[18:33]  <jwage> example
[18:33]  <jwage> you also may want situations where you access a relationship, to automatically inject another join
[18:33]  <jwage> or inject something in the select
[18:34]  <jwage> say you have complex select statements you don't want to repeat everytime, you can just include it in the relationship
[18:36]  <romanb> would you mind collecting some of those more complex examples in a ticket or the wiki so that we can look into it better? dont get me wrong, im just trying to see the need for this.
[18:38]  <romanb> and maybe we can also figure out the best syntax through proposals this way if we decide to add it.
[18:39]  <jwage> another one would if you have multiple active phonenumbers
[18:39]  <jwage> storing the active_phonenumber_id would not work anymore
[18:40]  <jwage> right now when i query for the data i just add a WITH to the join to only get the active phone numbers
[18:40]  <jwage> maybe it doesn't need to be any dql parts, but it needs to be more than orderby and indexby
[18:40]  <romanb> jwage: apart from that, i also want to make it possible to override a lot of predefined statements with custom SQL. so that you can override almost any pregenereated SQL statement with a custom one if you wish to do so (and then it's your obligation whether the SQL is portable or not)
[18:41]  <jwage> like the ability to specify a completely custom ON condition for the join, or append to it using WITH
[18:42]  <jwage> often i have joins where i have subsets of data in those joins that are limited by certain conditions..right now i just specify it in my dql in lots of places, but i would prefer to create a relationship with a verbose alias representing that relationship with the conditions i expect