Filtering the left hand combo box for "has_many"
  • I need a has_many relationship between 2 tables, but the left hand (''foreign") list of the admin combo box really needs to be a filter, based on the id of the candidate table.

    So if the foreign table were "schools", and the candidate "authorities" then the left list would be schools with an authority_id of the current authority admin view.

    I think this is possible, perhaps with the has_many property definition specifying a method on the foreign table. A form_fields() derived custom field (type 'multi') would do the trick, but with extra post methods I guess.

    If the former I'm not sure of the definition. Is is possible?
  • I'm not quite sure I totally understand but will give it a shot. It sounds like you want to customize the options on the left side to be something other then the default the has_many provides you which is the options_list method on the foreign model. The field the has_many generates is "multi" field which means it has an options property which the has_many relationship is automatically filling out. You can replace the options property with your own records in the form_fields method on your model.
  • Yes you got that right. I think I need to use the multi type definition in form_fields(), and test for edit mode, as the multi field filter won't be applicable until the record is saved. That also means an on_after routine to save the array.
  • I got exactly what I wanted with the multi field type - FuelCMS still has it!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!