0

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

4

1 回答 1

0

在 ActiveSacffold 控制器中,我添加了这个 AS 钩子方法......

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})”结束

于 2009-06-01T15:44:11.197 回答