parental_control
parental_control copied to clipboard
Association can't be used in default_value_for block
I'm using nice Phusion's default_value_for plugin. It is not possible to access parent object from within child's default_value_for block. This is because parental control fixes the association after object initialization, while default_value_for wraps initialize method. Example (this time checked in console);
class Face true
man.build_face
One may expect this code to return Face instance with :smiled attribute set to true. Instead exception is raised, as man is not set for face yet.
Is is possible to modify parental_control plugin to fix the association earlier?
Unfortunately, not without a lot more monkey patching of how active record works.
I'll have a think about it, as I think that in some cases we do want the Man instance set of Face instances earlier than it currently does it - I'm just not sure how yet. If you have any ideas, please do let me know.