Rails accepts_nested_attributes_for child doesn't have parent set when validating

前端 未结 4 1673
情书的邮戳
情书的邮戳 2021-02-04 12:50

I\'m trying to access my parent model in my child model when validating. I found something about an inverse property on the has_one, but my Rails 2.3.5 doesn\'t recognize it, s

4条回答
  •  隐瞒了意图╮
    2021-02-04 12:59

    check these sites, maybe they'll help you...

    Rails Nested Attributes Association Validation Failing

    accepts_nested_attributes_for child association validation failing

    http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

    it seems, rails will assign parent_id after child validation succeeds. (as parent has an id after it's saved)

    maybe worth trying this:

    child.parent.some_condition
    

    instead of self.parent.some_condition ... who knows...

提交回复
热议问题