为了处理通过关系的has

编程入门 行业动态 更新时间:2024-10-07 08:25:31
本文介绍了为了处理通过关系的has_many的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个型号:项目和任务(例如)与加盟模式:project_task使通过关系的has_many这样的任务可以跨项目共享

I have two models: project and task (for example) with a join model: project_task enabling a has_many through relationship so that tasks may be shared across projects.

我已指定的位置作为project_task模型的一个属性。现在,我希望能够通过一个给定的项目,以访问任务由他们在project_tasks表中的位置。

I have specified position as an attribute of the project_task model. Now I want to be able to access tasks by their position in the project_tasks table via a given project.

即。 project.tasks(上市在project_tasks表中的每个任务的位置排序)。

i.e. project.tasks (ordered by the position listed for each task in the project_tasks table).

这可能吗?

推荐答案

我想类似的东西,可以帮助你:

I think something like that can help you:

has_many :project_tasks has_many :tasks, :through => :project_tasks, :order => 'project_tasks.position'

更多推荐

为了处理通过关系的has

本文发布于:2023-08-03 14:42:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系

发布评论

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

>www.elefans.com

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