有没有更简洁的方式编写此代码:
> e = Entity.create(name: 'foo')
#<Entity id: 1, name: "foo", created_at: "2014-07-25 13:57:08", updated_at: "2014-07-25 13:57:08">
> l = Location.create(address: 'New York, NY')
#<Location id: 1, address: "New York, NY", created_at: "2014-07-25 13:57:08", updated_at: "2014-07-25 13:57:08">
> e.location = l
> e.save
这不起作用:
> Entity.create(name: 'foo').location.create(address: 'New York, NY')
实体has_one
位置(如果相关)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句