{"action":"opened","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/7720","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/7720/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/7720/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/7720/events","html_url":"https://github.com/yiisoft/yii2/issues/7720","id":61405789,"number":7720,"title":"ActiveRecord function fields() & getLinks() does not work","user":{"login":"dhiman252","id":8954468,"avatar_url":"https://avatars.githubusercontent.com/u/8954468?v=3","gravatar_id":"","url":"https://api.github.com/users/dhiman252","html_url":"https://github.com/dhiman252","followers_url":"https://api.github.com/users/dhiman252/followers","following_url":"https://api.github.com/users/dhiman252/following{/other_user}","gists_url":"https://api.github.com/users/dhiman252/gists{/gist_id}","starred_url":"https://api.github.com/users/dhiman252/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhiman252/subscriptions","organizations_url":"https://api.github.com/users/dhiman252/orgs","repos_url":"https://api.github.com/users/dhiman252/repos","events_url":"https://api.github.com/users/dhiman252/events{/privacy}","received_events_url":"https://api.github.com/users/dhiman252/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-14T04:29:30Z","updated_at":"2015-03-14T04:29:30Z","closed_at":null,"body":"I am using YII2 Rest API. I have a model class named Editorial which extends yii\\db\\ActiveRecord and implements Linkable Interface.\r\n\r\nthe fields method is as follows\r\n\r\npublic function fields() {        \r\n        return [\r\n            'id',\r\n            'title',\r\n            'description',\r\n            'user_id' => function(){\r\n                return $this->user;\r\n            },\r\n            'created' => function(){\r\n                return date('Y-m-d H:i:s',  $this->created);\r\n            },\r\n            'updated' => function(){\r\n                return date('Y-m-d H:i:s',  $this->created);\r\n            }\r\n        ];\r\n    } \r\n\r\npublic function getLinks(){\r\n        return [\r\n            Link::REL_SELF => Url::to(['/editorial/view', 'id' => $this->id], true)\r\n        ];\r\n    }\r\n\r\nI do have relations\r\n\r\n/**\r\n     * @return \\yii\\db\\ActiveQuery\r\n     */\r\n    public function getUser()\r\n    {\r\n        return $this->hasOne(User::className(), ['id' => 'user_id']);\r\n    }\r\n \r\n    /**\r\n     * @return \\yii\\db\\ActiveQuery\r\n     */\r\n    public function getEditorialComments()\r\n    {\r\n        return $this->hasMany(EditorialComments::className(), ['editorial_id' => 'id']);\r\n    }\r\n\r\n    /**\r\n     * @return \\yii\\db\\ActiveQuery\r\n     */\r\n    public function getEditorialDislikes()\r\n    {\r\n        return $this->hasMany(EditorialDislikes::className(), ['editorial_id' => 'id']);\r\n    }\r\n\r\n    /**\r\n     * @return \\yii\\db\\ActiveQuery\r\n     */\r\n    public function getEditorialLikes()\r\n    {\r\n        return $this->hasMany(EditorialLikes::className(), ['editorial_id' => 'id']);\r\n    }\r\n\r\nWhen I use the following query the fields and getlinks method does not work\r\n\r\nEditorial::find()\r\n                ->with('user',\r\n                    'editorialComments',\r\n                    'editorialComments.user',\r\n                    'editorialLikes',\r\n                    'editorialDislikes')\r\n                ->orderBy('created DESC')\r\n                ->asArray()\r\n                ->all()\r\n\r\nWhen i make use of ActiveDataprovider in my controller which extends yii\\rest\\Controller then the relations are not displayed although fields and getLinks function works correctly.\r\n\r\nreturn ActiveDataProvider([\r\n    'query' => Editorial::find()\r\n                ->with('user',\r\n                    'editorialComments',\r\n                    'editorialComments.user',\r\n                    'editorialLikes',\r\n                    'editorialDislikes')\r\n                ->orderBy('created DESC')\r\n]);\r\n\r\n\r\n\r\n\r\n"}}