ActiveScaffold - 指定嵌入式脚手架中的条件
我有一个项目模型和一个任务类型模型。 两者之间的关联通过 ProjectTaskType 模型进行 (由数据库中的链接/连接表支持,其中包含项目和项目的外键 任务类型)。
一个项目 has_many TaskTypes :通过 ProjectTaskType 和一个 TaskTypes has_many 项目:通过 ProjectTaskType。
我有一个带有嵌入式脚手架的视图,想要显示所有内容 属于给定项目的任务类型。
有人可以指导我如何为此编写条件吗?
<%= render
:active_scaffold => :task_type,
:label => 'Task Types',
:conditions => "TaskTypes which are associated with @project
through the ProjectTaskType" %>
我的过滤逻辑可以去其他地方吗?
谢谢
I have a Project model and a TaskType model.
Association between the two occurs through a ProjectTaskType model
(backed by a link/join table in the DB with foreign keys to both Projects and
TaskTypes).
A Project has_many TaskTypes :through ProjectTaskType, and a TaskTypes
has_many Projects :through ProjectTaskType.
I have a vew with an embedded scaffold and want to display all
TaskTypes belonging to a given Project.
Can someone quide me as to how I would write the conditions for this?
<%= render
:active_scaffold => :task_type,
:label => 'Task Types',
:conditions => "TaskTypes which are associated with @project
through the ProjectTaskType" %>
And can my filtering logic go elsewhere?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ActiveSacffold 控制器中,我添加了此 AS 挂钩方法...
def criteria_for_collection
子查询=“选择t.id
来自 #{TaskType.table_name} t, #{ProjectTaskTypes.table_name} ptt
其中 (t.id = ptt.task_type_id 和 ptt.project_id = #{project_id})"
"id in (#{subquery})"
结尾
In the ActiveSacffold controller I added this AS hook method...
def conditions_for_collection
subquery = "SELECT t.id
from #{TaskType.table_name} t, #{ProjectTaskTypes.table_name} ptt
where (t.id = ptt.task_type_id and ptt.project_id = #{project_id})"
"id in (#{subquery})"
end