{"action":"created","issue":{"url":"https://api.github.com/repos/akeeba/fof/issues/552","labels_url":"https://api.github.com/repos/akeeba/fof/issues/552/labels{/name}","comments_url":"https://api.github.com/repos/akeeba/fof/issues/552/comments","events_url":"https://api.github.com/repos/akeeba/fof/issues/552/events","html_url":"https://github.com/akeeba/fof/issues/552","id":103697322,"number":552,"title":"Relations during onAfterSave","user":{"login":"Skullbock","id":1104083,"avatar_url":"https://avatars.githubusercontent.com/u/1104083?v=3","gravatar_id":"","url":"https://api.github.com/users/Skullbock","html_url":"https://github.com/Skullbock","followers_url":"https://api.github.com/users/Skullbock/followers","following_url":"https://api.github.com/users/Skullbock/following{/other_user}","gists_url":"https://api.github.com/users/Skullbock/gists{/gist_id}","starred_url":"https://api.github.com/users/Skullbock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skullbock/subscriptions","organizations_url":"https://api.github.com/users/Skullbock/orgs","repos_url":"https://api.github.com/users/Skullbock/repos","events_url":"https://api.github.com/users/Skullbock/events{/privacy}","received_events_url":"https://api.github.com/users/Skullbock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-28T10:50:34Z","updated_at":"2015-08-31T07:30:46Z","closed_at":null,"body":"Hi @nikosdion , i was checking out the relations (in particular, the belongsTo in this case) in FOF3.\r\nI have a particular case which is not behaving as expected, and wanted to know if it's by design or i'm doing something wrong.\r\n\r\nI have this usecase:\r\n\r\n1) **Orders** model with a hasMany('payments') relationship\r\n2) **Payments** model with a belongsTo('order', 'Orders') relationship\r\n\r\nnow, when i do \r\n\r\n```php\r\n<?php\r\n$paymentModel->find(1)->order->toJson();\r\n?>\r\n```\r\n\r\nit works as expected. \r\nBut if i try:\r\n\r\n```php\r\n<?php\r\n/**\r\n * Model for Payments\r\n */\r\nclass Payments extends DataModel\r\n{\r\n   .....\r\n    /**\r\n     * Whenever we save a payment, let's move the order status too\r\n     */\r\n    protected function onAfterSave() {\r\n    \tif ($this->order && $this->status != $this->order->status) {\r\n    \t\t$this->order->status = $this->status;\r\n    \t\t$this->order->save();\r\n    \t}\r\n    }\r\n}\r\n?>\r\n```\r\n\r\nit doesn't work. From my research i got that is because the parentModel property in the relation class is not populated with the current item, but is still empty. \r\n\r\nAm i missing something?"},"comment":{"url":"https://api.github.com/repos/akeeba/fof/issues/comments/136287524","html_url":"https://github.com/akeeba/fof/issues/552#issuecomment-136287524","issue_url":"https://api.github.com/repos/akeeba/fof/issues/552","id":136287524,"user":{"login":"Skullbock","id":1104083,"avatar_url":"https://avatars.githubusercontent.com/u/1104083?v=3","gravatar_id":"","url":"https://api.github.com/users/Skullbock","html_url":"https://github.com/Skullbock","followers_url":"https://api.github.com/users/Skullbock/followers","following_url":"https://api.github.com/users/Skullbock/following{/other_user}","gists_url":"https://api.github.com/users/Skullbock/gists{/gist_id}","starred_url":"https://api.github.com/users/Skullbock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skullbock/subscriptions","organizations_url":"https://api.github.com/users/Skullbock/orgs","repos_url":"https://api.github.com/users/Skullbock/repos","events_url":"https://api.github.com/users/Skullbock/events{/privacy}","received_events_url":"https://api.github.com/users/Skullbock/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T07:30:46Z","updated_at":"2015-08-31T07:30:46Z","body":"I'll try that, but what's happening there is that the order variable is not populated, so even doing order->status results in a \"not defined property\" warning"}}