对于一个has_one关联,我可以建立一个这样的关联:
foo.build_bar()
我应该如何建立一个has_one, through:协会?
例如:
class Foo
has_one :bar
has_one :baz, through: :bar
end
我应该如何构建baz?在这个例子中foo.build_baz,我得到了一个No Method Error.
这里的文档说:
当你声明一个 has_one 关联时,声明类会自动获得与该关联相关的四个方法:
association(force_reload = false)
association=(associate)
build_association(attributes = {})
create_association(attributes = {})
然而,情况似乎并非如此。使用 Pry 反省FooI can see no such method is added as it would be on a has_onewithout a through:.