{"action":"closed","issue":{"url":"https://api.github.com/repos/akeeba/fof/issues/532","labels_url":"https://api.github.com/repos/akeeba/fof/issues/532/labels{/name}","comments_url":"https://api.github.com/repos/akeeba/fof/issues/532/comments","events_url":"https://api.github.com/repos/akeeba/fof/issues/532/events","html_url":"https://github.com/akeeba/fof/issues/532","id":97060918,"number":532,"title":"Eager loading constraints?","user":{"login":"compojoom","id":693770,"avatar_url":"https://avatars.githubusercontent.com/u/693770?v=3","gravatar_id":"","url":"https://api.github.com/users/compojoom","html_url":"https://github.com/compojoom","followers_url":"https://api.github.com/users/compojoom/followers","following_url":"https://api.github.com/users/compojoom/following{/other_user}","gists_url":"https://api.github.com/users/compojoom/gists{/gist_id}","starred_url":"https://api.github.com/users/compojoom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/compojoom/subscriptions","organizations_url":"https://api.github.com/users/compojoom/orgs","repos_url":"https://api.github.com/users/compojoom/repos","events_url":"https://api.github.com/users/compojoom/events{/privacy}","received_events_url":"https://api.github.com/users/compojoom/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-24T14:06:57Z","updated_at":"2015-07-25T14:00:10Z","closed_at":"2015-07-25T14:00:10Z","body":"According to the docs:\r\nhttps://github.com/akeeba/fof/wiki/Model-relations\r\nInstead of passing a plain array, pass a hash array. The key is the relation name, the value is a callable (closure or callback) which acts upon the eager loading query. For example:\r\n\r\n// Load articles and their published comments only\r\n$articles = $model->with(array(\r\n    'comments' => function ($query) {\r\n        $query->where('enabled = 1');\r\n    }\r\n))->get();\r\n\r\nIf I understand the above code correctly, it should load all articles and for each loaded article we will get only the relations where we have comments?\r\n\r\nIf my understanding of the above is correct, then FOF has a bug. \r\n\r\nIn my case I do this:\r\n```php\r\n$apartments = $this->getContainer()->factory->model('Apartments')->with(array(\r\n\t'bookings' => function ($query) {\r\n\t\t$query->where('enabled = 1');\r\n\t}\r\n))->get();\r\n```\r\n\r\nSo I expect to get all apartments and for each apartment to get only the bookings that are active. But this has no effect on the bookings actually - I always get all bookings. \r\n\r\nI actually did a var_dump in the callback function and $query is not a Query object, but a model object??? \r\n\r\nSo the callback should actually be:\r\n```php\r\n$apartments = $this->getContainer()->factory->model('Apartments')->with(array(\r\n\t'bookings' => function ($model) {\r\n\t\t$model->setState('enabled', 1);\r\n\t}\r\n))->get();\r\n```\r\n\r\nIs this a bug in FOF or a bug in the docs?"}}