Ruby on Rails 3 (3.1) ActiveModel 关联(无表嵌套模型)

编程入门 行业动态 更新时间:2024-10-28 04:18:09
本文介绍了Ruby on Rails 3 (3.1) ActiveModel 关联(无表嵌套模型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何实现 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 关联(无表嵌套模型)

本文发布于:2023-10-28 22:37:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   模型   Rails   Ruby   ActiveModel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!