{"action":"created","issue":{"url":"https://api.github.com/repos/analogueorm/analogue/issues/56","labels_url":"https://api.github.com/repos/analogueorm/analogue/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/analogueorm/analogue/issues/56/comments","events_url":"https://api.github.com/repos/analogueorm/analogue/issues/56/events","html_url":"https://github.com/analogueorm/analogue/pull/56","id":107462497,"number":56,"title":"prevent error when an entity-map has a method that is not for a relationship","user":{"login":"Evertt","id":1267282,"avatar_url":"https://avatars.githubusercontent.com/u/1267282?v=3","gravatar_id":"","url":"https://api.github.com/users/Evertt","html_url":"https://github.com/Evertt","followers_url":"https://api.github.com/users/Evertt/followers","following_url":"https://api.github.com/users/Evertt/following{/other_user}","gists_url":"https://api.github.com/users/Evertt/gists{/gist_id}","starred_url":"https://api.github.com/users/Evertt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Evertt/subscriptions","organizations_url":"https://api.github.com/users/Evertt/orgs","repos_url":"https://api.github.com/users/Evertt/repos","events_url":"https://api.github.com/users/Evertt/events{/privacy}","received_events_url":"https://api.github.com/users/Evertt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-21T08:07:01Z","updated_at":"2015-09-21T09:13:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/analogueorm/analogue/pulls/56","html_url":"https://github.com/analogueorm/analogue/pull/56","diff_url":"https://github.com/analogueorm/analogue/pull/56.diff","patch_url":"https://github.com/analogueorm/analogue/pull/56.patch"},"body":"Well the title is a bit confusing, because the place I encountered this error actually did have to do with a relationship.\r\n\r\nYou see in a project I was working on, I needed to create a new type of relationship called `HasTranslations`. It was based on the `HasMany` relationship, with the difference that the related translations that were found were put directly on the entity, instead of via a `translations` attribute on the entity.\r\n\r\nSo in order to make this work I needed to make a BaseEntityMap which has a method like this:\r\n\r\n    public function hasTranslations($entity, $relatedTable, $foreignKey = 'foreign_key', $localKey = null)\r\n    {\r\n        $foreignKey = $foreignKey ?: $this->getForeignKey();\r\n\r\n        $relatedMap = new EntityMap;\r\n\r\n        $relatedMap->setTable($relatedTable);\r\n\r\n        $table = $relatedTable.'.'.$foreignKey;\r\n\r\n        $localKey = $localKey ?: $this->getKeyName();\r\n\r\n        return with(new HasTranslations($relatedMap, $entity, $table , $localKey))\r\n            ->where('model', $this->getMorphClass())\r\n            ->where('locale', 'eng');\r\n    }\r\n\r\nAnd that would trigger an error, because the first argument did not have the Entity class type. And if it did, well then Analogue would assume I'm trying to do something I'm not."},"comment":{"url":"https://api.github.com/repos/analogueorm/analogue/issues/comments/141920158","html_url":"https://github.com/analogueorm/analogue/pull/56#issuecomment-141920158","issue_url":"https://api.github.com/repos/analogueorm/analogue/issues/56","id":141920158,"user":{"login":"Evertt","id":1267282,"avatar_url":"https://avatars.githubusercontent.com/u/1267282?v=3","gravatar_id":"","url":"https://api.github.com/users/Evertt","html_url":"https://github.com/Evertt","followers_url":"https://api.github.com/users/Evertt/followers","following_url":"https://api.github.com/users/Evertt/following{/other_user}","gists_url":"https://api.github.com/users/Evertt/gists{/gist_id}","starred_url":"https://api.github.com/users/Evertt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Evertt/subscriptions","organizations_url":"https://api.github.com/users/Evertt/orgs","repos_url":"https://api.github.com/users/Evertt/repos","events_url":"https://api.github.com/users/Evertt/events{/privacy}","received_events_url":"https://api.github.com/users/Evertt/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T09:13:53Z","updated_at":"2015-09-21T09:13:53Z","body":"This is an example of an actual entitymap I’m using this for:\n\n<?php namespace App\\Model\\Maps;\n\nuse App\\Model\\Entities\\I18n;\nuse App\\Model\\Entities\\News;\nuse App\\Model\\Entities\\Page;\nuse App\\Model\\Entities\\PrimaryVisual;\nuse App\\Model\\Entities\\Visual;\n\nclass NewsMap extends EntityMap\n{\n    protected $with = ['translations', 'primaryVisual'];\n\n    public function translations(News $news)\n    {\n        return $this->hasTranslations($news, 'i18n');\n    }\n\n    public function pages(News $news)\n    {\n        return $this->belongsToMany($news, Page::class, 'pages_news');\n    }\n\n    public function visuals(News $news)\n    {\n        return $this->morphMany($news, Visual::class, 'model', 'model');\n    }\n\n    public function primaryVisual(News $news)\n    {\n        return $this->morphOne($news, PrimaryVisual::class, 'model', 'model')\n            ->orderBy('primary', 'desc')->orderBy('type_is_default', 'desc');\n    }\n}\n\nThe second parameter of $this->hasTranslations specifies which table it should use.\nIs this all the information you need? Or do you also need to see my HasTranslations relationship-class?\n\n\n> On 21 Sep 2015, at 11:05, Rémi Collin <notifications@github.com> wrote:\n> \n> Hey Evertt. The check fails is an error with the scrutinizer app, the travis CI is ok, which is the one which matters :) .\n> \n> I'm not sure about this error. Can you please share your code for the relationship in the actual entity map ?\n> \n> The way analogue works, it parses the EntityMap's user methods and treat the ones with the first argument type hinted to the Entity it managed to be relationships. I never tested this with an intermediate BaseEntityMap, it may be related or not.\n> \n> —\n> Reply to this email directly or view it on GitHub <https://github.com/analogueorm/analogue/pull/56#issuecomment-141918473>.\n> \n\n"}}