开发者

Rails 2.3.x belongs_to association required by default?

开发者 https://www.devze.com 2023-01-13 23:46 出处:网络
In Rails 2.3.8, if I specify a relationship in my model as: belongs_to :foo Is that implicitly required now? If I want this model to always specify mymodel.foo when a new record is being validated,

In Rails 2.3.8, if I specify a relationship in my model as:

belongs_to :foo

Is that implicitly required now? If I want this model to always specify mymodel.foo when a new record is being validated, am I still required to use validates_p开发者_JAVA百科resence_of :foo?


No, it's not implicitly required; you need to validate the presence if needed.

Sometimes you want to have a belongs_to relationship where the parent_id is nullable, so these are treated as separate things.

0

精彩评论

暂无评论...
验证码 换一张
取 消