开发者

Rails references

开发者 https://www.devze.com 2023-01-19 20:41 出处:网络
Let\'s say that you have a foreign key called COMPANY_ID in the table PERSON.In the model PERSON, can you write?

Let's say that you have a foreign key called COMPANY_ID in the table PERSON. In the model PERSON, can you write?

validates_presence_of :company_id

or

validates_presence_of :company

or

both?

Which is the prefer开发者_运维问答red and why?


Prefere validates the foreign_key. It's better because there are no association made so 1 SQL request less.

0

精彩评论

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