parental_control icon indicating copy to clipboard operation
parental_control copied to clipboard

Association can't be used in default_value_for block

Open pepawel opened this issue 15 years ago • 1 comments

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?

pepawel avatar Jul 27 '09 18:07 pepawel

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.

h-lame avatar Jul 28 '09 11:07 h-lame