Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Model returns all relations, even if not queried
  • Hi there,
    Thank you for this great framework!! I am really looking forward to FuelPHP 2 :) I am wondering if following is a bug. For example, Model_User extends \Orm\Model and has two relations Model_Post and Model_Comment.
    If I make a query $user = Model_User::query()->where('id', 1)->get_one(); $user will contain all relations even if they are not part of a query, that is, I will be able to access print_r($user->posts) if my question makes sense, is this is a bug, or its just a way that ORM works?
  • No, it doesn't. It has a feature called 'lazy loading', which makes sure that if you request a relation that hasn't been loaded yet, it will load it on the fly. If you enable the profiler you'll see it lauches a second query. And printing $user->posts is requesting it.

Howdy, Stranger!

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

In this Discussion