本文介绍了为了处理通过关系的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
发布评论