{"action":"closed","issue":{"url":"https://api.github.com/repos/FriendsOfCake/crud/issues/287","labels_url":"https://api.github.com/repos/FriendsOfCake/crud/issues/287/labels{/name}","comments_url":"https://api.github.com/repos/FriendsOfCake/crud/issues/287/comments","events_url":"https://api.github.com/repos/FriendsOfCake/crud/issues/287/events","html_url":"https://github.com/FriendsOfCake/crud/issues/287","id":91200480,"number":287,"title":"Auto-loading related Tables","user":{"login":"davidyell","id":49889,"avatar_url":"https://avatars.githubusercontent.com/u/49889?v=3","gravatar_id":"","url":"https://api.github.com/users/davidyell","html_url":"https://github.com/davidyell","followers_url":"https://api.github.com/users/davidyell/followers","following_url":"https://api.github.com/users/davidyell/following{/other_user}","gists_url":"https://api.github.com/users/davidyell/gists{/gist_id}","starred_url":"https://api.github.com/users/davidyell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidyell/subscriptions","organizations_url":"https://api.github.com/users/davidyell/orgs","repos_url":"https://api.github.com/users/davidyell/repos","events_url":"https://api.github.com/users/davidyell/events{/privacy}","received_events_url":"https://api.github.com/users/davidyell/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-26T09:18:04Z","updated_at":"2015-07-21T21:45:23Z","closed_at":"2015-07-21T21:45:23Z","body":"**Scenario**\r\nI've made my admin index view and baked some views. It so happens that this table Examples, has a `status_id` field which relates to the Statuses table. This data isn't loaded.\r\n\r\n**What I did**\r\nIn my AppController I made a method which I called from my `beforeFilter`.\r\n\r\n```php\r\nprotected function addRelatedTables()\r\n{\r\n    if (!is_array($this->paginate['contain']) || !isset($this->paginate['contain'])) {\r\n        $this->paginate['contain'] = [];\r\n    }\r\n\r\n    $this->Crud->on('beforePaginate', function (Event $event) {\r\n        foreach($this->{$this->modelClass}->associations() as $table => $association) {\r\n            $this->paginate['contain'] = array_merge(\r\n                $this->paginate['contain'],\r\n                [$this->{$this->modelClass}->association($table)->name()]\r\n            );\r\n        }\r\n    });\r\n}\r\n```\r\n\r\n**Suggestions**\r\nIs it worth making this into a listener in a similar vein to the RelatedModelsListener?\r\n\r\n**Concerns**\r\nWith so many ways to configure the Paginator component, my code example above relies on the shortcut pagination array, and I don't know if it would be merged accurately with someone using the paginator component directly, such as `$this->Paginator->paginate($Table, $optionsArray)`.\r\n\r\nAlso I'd be interested in thoughts on how configure such a thing in a more application wide way, to prevent controller specific configuration, which, to me, defeats the point of the Crud plugin."}}