Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Relation of relation


  • If I Have 3 Models wich extends ORM
    1. Model_Biblio
    properties: biblio_id(pk), title
    has_many (items)
    2. Model_Item
    properties:item_id(pk), biblio_id
    belongs_to (biblio)
    has_many(printqueue)
    3. Model_Printqueue
    properties:id(pk), item_id
    belongs_to (item)

    when I perform $item=Model_Printqueue::find($id)
    Can I somehow get 

    $item->biblio->title??

    thanks for your replies
  • HarroHarro
    Accepted Answer
    Your $item here is not an instance of Model_Item, but of Model_Printqueue. So it should be

    echo $item->item->biblio->title;

    And that should work without problems.

    If the related object isn't loaded yet, it will be loaded dynamically. If will depend on your application and database design whether it's ok to have lazy loading, or it is faster to include the related modules on the find:

    $item=Model_Printqueue::find($id, array('related' => array('item', 'item.biblio')));
  • Thanks You.., I'll try it
  • it works.., tQ

Howdy, Stranger!

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

In this Discussion