I don't have a lot to offer to this subject except to say that in my experience of building declarative bidirectional relationships in Javascript (to proxy AR records!) I found that "promoting" the associations to a full-blown model was quite clean. If done directly in AR, I could imagine something like this:
in app/models/dangerous_circus_tricks.rb class DangerousCircusTrick < ActiveRecord::AssociationModel associate ExtremeJuggler, [FlamingSticks] def adequately_insured? flaming_sticks < 3 || extreme_juggler.experience == :expert end end Complex relationships (particularly with bidirectionality) sometimes warrant a dedicated model -even if the particulars of the ORM layer don't require a dedicated table. I suspect that such an approach would extend well into ActiveResource and other non-RDBMS stores. It could even be used to model mixed associations (an AR record associated with an ActiveRes model). On Dec 3, 10:59 am, "Murray Steele" <[EMAIL PROTECTED]> wrote: > 2008/12/2 acechase <[EMAIL PROTECTED]> > > > > > > > On Dec 1, 12:14 pm, "Michael Koziarski" <[EMAIL PROTECTED]> wrote: > > > > As for the bi-directionality of in-memory AR objects, you should check > > > > out the parental-control plugin, which while incomplete, covers quite > > > > a bit of what is needed to support bi-directional associations in > > > > rails: > > > >http://github.com/h-lame/parental_control/tree/master > > > > Nice! I'd love to see something along these lines baked right in to 2.3 > > > > -- > > > Cheers > > > > Koz > > > Three cheers to that! h-lame has done some really good work getting > > the parental_control plugin working, but I think it would make > > hammering out the trickier bits much easier if it was part of core. > > Ah-ha! Now I understand why my little un-announced plugin suddenly got some > watchers on github ;) > > So, here seems like as good a place as any to thrash it out. What do we > think I/we'd need to do to get it into core? As someone pointed out, it's > pretty incomplete so I'm sure I've not covered all the edge cases, although > I think it does a pretty good job of giving up if it can't find something > that it thinks is the right inverse / reciprocal relationship (and we're > using it in a production app here and it's yet to fall over). > > The first natural extension to me would be to allow for :inverse options on > association definitions that would allow for getting round trying to work it > out, e.g. something like: > > class FlamingStick < ActiveRecord::Base > belongs_to :extreme_juggler, :inverse => :flaming_sticks > end > > class ExtremeJuggler < ActiveRecord::Base > has_many :flaming_sticks, :inverse => :extreme_juggler > end > > Although, for these simple cases it does seem like extra work that the > framework should be able to work it out for you, so I don't think I'm hugely > in favour of dropping the "magic" auto-detection. > > Anything else / anyone else used it and spotted stuff I haven't? > > Cheers, > > Muz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---