Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Working with ORM views, \ORM\Model::views
  • While I'm checking \ORM\Model code found a method called views, anybody knows how it works? Thanks
  • Just like table(), observers() and properties() it checks the model for the $_views property and returns them (as the docblock says). Now as to what they are for: you can define database views based on your normal table with additional columns that may be fetched. You set these in the class definition using:
    // example where I have an extra column counting the number of another model that belong to the base model
     protected static $_views = array(
      'counted' => array(
       'columns' => array('transaction_count'),
      ),
     );
    

    And when querying:
    $logs = Model_Log::query()->use_view('counted')->get();
    

Howdy, Stranger!

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

In this Discussion