views:

268

answers:

1

Hi,

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

A: 

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

Paul