如何实现 ActiveModel 关联(无表嵌套模型)?
How to impliment ActiveModel associations (tableless nested models)?
例如:
book has many chapters使用 ActiveRecord,我将创建两个模型并将它们与 has_many 和 belongs_to 相关联.但是 ActiveModel 没有这样的功能.我该如何实施?
With ActiveRecord I would create two models and assosiate them with has_many and belongs_to. But ActiveModel doesn't have such functionality. How can I implement this?
推荐答案你不能那样做.它不是活动记录.
You simply can't do it that way. It is not active record.
您可以在以下位置查看 ActiveModel 文档(和源代码):
You can check ActiveModel documentation (and source code) at :
github/rails/rails/tree/master/activemodel
我想你必须用老式的方式来做,使用一系列章节和章节中对本书的引用.
I guess you have to do it old fashion way, using an array of chapters and a reference to the book in the chapters.
希望这会有所帮助!
更多推荐
Ruby on Rails 3 (3.1) ActiveModel 关联(无表嵌套模型)
发布评论