[Nitro] Unintuitive Og modeling
Brian Davis
brian.william.davis at gmail.com
Fri Mar 2 00:04:22 EST 2007
NOTE: I posted this at the Google Groups interface, but my message has
languished in the ether.
I spoke with Kashia earlier about this and he encouraged me to post
this to the mailing list.
Consider the following model definition:
--------------------
class User
...
many_to_many :buddies, User, :foreign_name => :buddies
many_to_many :buddies_pending_confirmation, User, :foreign_name
=> :buddies_requested
many_to_many :buddies_requested, User, :foreign_name
=> :buddies_pending_confirmation
...
end
--------------------
This is a reflexive join with several distinct relationships that
happen to join to objects of the same class. My issue is that, with
Og, only one join table is created to model *all* of these
relationship: og_user_user. Because of this, the relationships are
essentially mirrored. Thus, if a user is added to my
'buddies_pending_confirmation' queue, they also appear in my 'buddies'
and 'buddies_requested' lists, although this is precisely the opposite
of the intended behavior.
Kashia showed me a hack that circumvents this behavior (by defining a
self-join class for each of the relationships above), but we both
found it to be, well, a hack. It lacked the clarity and intuitiveness
of the code above.
My suggestion, then, is to perhaps name join tables not by their
associated types, but by their given label (the first argument to
'many_to_many'). Thus, my 'og_user_user' table right now would
actually be three tables, 'og_user_buddies',
'og_user_buddies_pending_confirmation' and
'og_user_buddies_requested'.
Please let me know if this is unreasonable, stupid or unclear. Also,
if there's something I'm just altogether missing, set me straight.
Thanks,
Brian
More information about the Nitro-general
mailing list