Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fieldset / ORM / Related Model
  • Hi, I have a doubt. 
    I have a model A that belongs_to a model B.

    When I'm creating a new A record, I use the fieldset class to build the form, but I don't know if there is a way to add the relation to the fieldset.

    Ex: A select field with all the B records in the A fieldset form.
  • HarroHarro
    Accepted Answer
    Not automatically.

    You will have to define the form field type in the model properties as 'select', and then populate the form field options with the correct key/value pairs.

    This is an example:

    $form->field('chairman_id')->set_options(\DB::select('id', array(\DB::expr('CONCAT(surname,", ",initials," ",prefix)'), 'name'))->from('people')->where('type', '=', 'E')->order_by('name', 'ASC')->execute()->as_array('id', 'name'));

    Which will create an array with 'id' => 'name' and assigns it to the select.
  • hmm, ok. Thanks.
    It's working now.

Howdy, Stranger!

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

In this Discussion