trestle icon indicating copy to clipboard operation
trestle copied to clipboard

Associations

Open martio opened this issue 6 years ago • 1 comments

Hi,

I have models in my application with the has_many association: car and parts. Car has many parts.

How to go from a car resource to parts?

Trestle.resource(:cars) do
  table do
    column :id
    column :name
    actions do |toolbar, instance, admin|
      toolbar.link 'Parts', "/admin/parts?&q=#{instance.id}", target: '_blank'
    end
  end
end
Trestle.resource(:parts) do
   search do |query|
    if query
      Part.where('car_id = ?', query)
    else
      Part.all
    end
  end

  table do
    column :name
    actions
  end
end

The right way?

martio avatar Dec 03 '18 15:12 martio

In cars admin resource - you can add a collectionselect Or collectioncheckbox You will then get a list of parts to select or check in the add new car form. I shall paste code tomorrow morning or you can google for - collection select trestle admin.

karan-ta avatar Sep 07 '19 15:09 karan-ta