what would happen if you use belongs_to without having a corresponding has_one?

后端 未结 1 1607
栀梦
栀梦 2021-02-13 22:32

I have a core model for an Item, and a script to populate it from a custom source (think, RSS feed). In the feed, each Item is identified with a guid;

相关标签:
1条回答
  • 2021-02-13 23:17

    It doesn't matter.

    belongs_to simply adds some methods to the ItemFeedInfo class. You know when you do item_feed_info.items.find_all... The items is just a method which got dynamically added when you called belongs_to.

    If you don't modify the Item class, then you simply won't be adding the methods on the other side. You won't be able to do item.item_feed_infos.find_all, because without adding has_many :item_feed_infos, that method won't have been added to the Item class, but if you never actually need to do this, it won't matter.

    0 讨论(0)
提交回复
热议问题