Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ActiveRecord Includes (more than one)
  • This is probably a question for elsewhere, so I apologies but I've got: in Controller_Vehicles action_index()
    $vehicles = Model_Vehicle::find('all', array(
      'offset' => Pagination::$offset,
      'limit' => Pagination::$per_page,
      'include' => array('propellant', 'type'),
    ));
    

    in Model_Vehicle I've got:
    protected $belongs_to = array('propellant', 'type');
    

    which should connect one vehicle with the propellants and types tables (can't use fuel, so I chose propellants!). in the view I've got
    <?php echo ($vehicle->type_id != 0) ? $vehicle->type->name : 'None'; ?>
    <?php echo ($vehicle->propellant_id != 0) ? $vehicle->propellant->name : 'None'; ?>
    

    I'm getting no errors, but it's only outputting the first $vehicle->type->name and I can't get $vehicle->propellant->name displayed. I'm guessing it's something in the Controller_Vehicle include - I've tried all sorts of things there! Yours,
    Chris
  • I think I've fixed this by removing the include statement completely and relying on the model behaviour of has_many or belongs_to.

Howdy, Stranger!

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

In this Discussion