Skip to content
A plugin for rails that allows has_one, has_many and certain belongs_to associations to share instances of the "parent" model to the "child" model via the association.
Latest commit 69e0178 Aug 7, 2009 @h-lame [#5] Do nothing in terms of reciprocal setting if we are presented wi…
…th something that's not an ActiveRecord::Base object.



Using parental control your associations will share model instances with each other where appropriate.  For example, when using a parent to fetch a child, the child will return the same parent instance if you ask it for it's parent, rather than fetching it from the database.

This might increase performance.  It might not.  It might make it easier to do things where a child relies on a parent for validation, and you make changes to both parent and child before saving.

So far it works for has_many and has_one (not :through) associations.  It also works for belongs_to asociations where the reciprocal association on the parent is a has_one.

For polymorphic associations it works for the belongs_to ends, but not the has_one or has_many ends of the association.



class Man < ActiveRecord::Base
  has_one :face

class Face < ActiveRecord::Base
  belongs_to :man

m = Man.first
f = m.face == # => true = 'Dave'

Without parental_control == # => false : m and are different instances of Man.first :(

With parental_control == # => true : m and are the same instances of Man.first :)

Copyright (c) 2008 Murray Steele, released under the MIT license
Something went wrong with that request. Please try again.