{"action":"created","comment":{"url":"https://api.github.com/repos/obophp/obo/pulls/comments/39918682","id":39918682,"diff_hunk":"@@ -59,38 +58,99 @@ public function findEntities(\\obo\\Carriers\\QuerySpecification $specification = n\n      * @return int\n      */\n     public function countEntities(\\obo\\Carriers\\QuerySpecification $specification = null) {\n-        if ($specification === null) $specification = new \\obo\\Carriers\\QuerySpecification();\n         $ownedEntityClassName = $this->entityClassNameToBeConnected;\n         $ownedEntityManagerName = $ownedEntityClassName::entityInformation()->managerName;\n-        return $ownedEntityManagerName::countRecords($this->constructSpecification(\\obo\\Carriers\\QueryCarrier::instance()->addSpecification($specification)));\n+        return $ownedEntityManagerName::countRecords($this->createSpecification($specification));\n     }\n \n     /**\n-     * @param \\obo\\Carriers\\QueryCarrier $specification\n+     * @param \\obo\\Interfaces\\IQuerySpecification $specification\n      * @return \\obo\\Carriers\\QueryCarrier\n      */\n-    public function constructSpecification(\\obo\\Carriers\\QueryCarrier $specification = null) {\n+    public function createSpecification(\\obo\\Interfaces\\IQuerySpecification $specification = null) {\n         $ownedEntityClassName = $this->entityClassNameToBeConnected;\n+        $ownedEntityManger = $ownedEntityClassName::entityInformation()->managerName;\n         $ownerPrimaryPropertyName = $this->owner->entityInformation()->primaryPropertyName;\n         $ownedPropertyNameForSoftDelete = $ownedEntityClassName::entityInformation()->propertyNameForSoftDelete;\n \n-        $query = $specification === null ? \\obo\\Carriers\\QueryCarrier::instance() : $specification;\n+        if ($specification === null) {\n+            $specification = $ownedEntityManger::queryCarrier();\n+        } else {\n+            $specification = $ownedEntityManger::queryCarrier()->addSpecification($specification);\n+        }\n+\n+        if ($this->connectViaPropertyWithName !== \"\") {\n+            $specification->where(\"AND {{$this->connectViaPropertyWithName}} = %s\", $this->owner->primaryPropertyValue());\n+            if ($this->ownerNameInProperty !== \"\") $specification->where(\"AND {{$this->ownerNameInProperty}} = %s\", $this->owner->className());\n+        } elseif ($this->connectViaRepositoryWithName !== \"\") {\n+            $specification->where(\"{*{$this->connectViaRepositoryWithName}:{$this->owner->entityInformation()->repositoryName}*} = %s\", $this->owner->primaryPropertyValue());\n+        }\n+\n+        if ($this->sortVia !== null) $specification->orderBy($this->sortVia);\n \n-        if ($this->connectViaPropertyWithName !== null) {\n-            $query->where(\"AND {{$this->connectViaPropertyWithName}} = %s\", $this->owner->$ownerPrimaryPropertyName);\n-            if ($this->ownerNameInProperty !== null) $query->where(\"AND {{$this->ownerNameInProperty}} = %s\", $this->owner->className());\n-        } elseif ($this->connectViaRepositoryWithName !== null){\n-            if ($ownedPropertyNameForSoftDelete !== \"\") {\n-                $softDeleteJoinQuery = \"AND [{$ownedEntityClassName::entityInformation()->repositoryName}].[{$ownedEntityClassName::informationForPropertyWithName($ownedPropertyNameForSoftDelete)->columnName}] = %b\";\n-                $query->join(\"JOIN [{$this->connectViaRepositoryWithName}] ON [{$this->owner->entityInformation()->repositoryName}] = %s AND [{$ownedEntityClassName::entityInformation()->repositoryName}] = [{$ownedEntityClassName::informationForPropertyWithName($ownedEntityClassName::entityInformation()->primaryPropertyName)->columnName}]\" . $softDeleteJoinQuery, $this->owner->$ownerPrimaryPropertyName, FALSE);\n+        return $specification ;\n+    }\n+\n+    public function add(\\obo\\Entity $entity) {\n+        if ($this->connectViaPropertyWithName !== \"\") {\n+            $entity->setValueForPropertyWithName($this->owner, $this->connectViaPropertyWithName);\n+            if ($this->ownerNameInProperty !== \"\") $entity->setValueForPropertyWithName($this->owner->className(), $this->ownerNameInProperty);\n+\n+            if ($this->owner->isBasedInRepository()) {\n+                $entity->save();\n             } else {\n-                $query->join(\"JOIN [{$this->connectViaRepositoryWithName}] ON [{$this->owner->entityInformation()->repositoryName}] = %s AND [{$ownedEntityClassName::entityInformation()->repositoryName}] = [{$ownedEntityClassName::informationForPropertyWithName($ownedEntityClassName::entityInformation()->primaryPropertyName)->columnName}]\", $this->owner->$ownerPrimaryPropertyName);\n+                \\obo\\Services::serviceWithName(\\obo\\obo::EVENT_MANAGER)->registerEvent(\n+                    new \\obo\\Services\\Events\\Event([\n+                        \"onObject\" => $this->owner,\n+                        \"name\" => \"afterInsert\",\n+                        \"actionAnonymousFunction\" => function () use ($entity) {\n+                            $entity->save();\n+                        },\n+                        \"actionArguments\" => [],\n+                    ])\n+                );\n             }\n+        } elseIf ($this->connectViaRepositoryWithName !== \"\") {\n+            if (!$entity->isBasedInRepository()) $entity->save();\n+\n+            if ($this->owner->isBasedInRepository()) {\n+                $this->createRelationshipInRepositoryForEntity($entity);\n+            } else {\n+                \\obo\\Services::serviceWithName(\\obo\\obo::EVENT_MANAGER)->registerEvent(\n+                    new \\obo\\Services\\Events\\Event([\n+                        \"onObject\" => $this->owner,\n+                        \"name\" => \"afterInsert\",\n+                        \"actionAnonymousFunction\" => function () use ($entity) {\n+                            $this->createRelationshipInRepositoryForEntity($entity);\n+                        },\n+                        \"actionArguments\" => [],\n+                    ])\n+                );\n+            }\n+        } else {\n+            throw new \\obo\\Exceptions\\Exception(\"This relationship is not well configured\");\n         }\n+    }\n \n-        if ($this->sortVia !== null) $query->orderBy($this->sortVia);\n+    public function remove(\\obo\\Entity $entity) {\n+        if ($this->connectViaPropertyWithName !== \"\") {\n+            $entity->setValueForPropertyWithName(null, $this->connectViaPropertyWithName);\n+            $entity->save();\n+        } elseIf ($this->connectViaRepositoryWithName !== \"\") {\n+            $ownerManagerName = $this->owner->entityInformation()->managerName;\n+            $ownerManagerName::dataStorage()->removeRelationshipBetweenEntities($this->connectViaRepositoryWithName, [$this->owner, $entity]);\n+        } else {\n+            throw new \\obo\\Exceptions\\Exception(\"This relationship is not well configured\");\n+        }\n+    }\n \n-        return $query;\n+    /**\n+     * @param \\obo\\Entity $entity\n+     * @return void\n+     */\n+    protected function createRelationshipInRepositoryForEntity(\\obo\\Entity $entity) {\n+        $ownerManagerName = $this->owner->entityInformation()->managerName;\n+        $ownerManagerName::dataStorage()->createRelationshipBetweenEntities($this->connectViaRepositoryWithName, [$this->owner, $entity]);\n     }\n \n-}\n+}","path":"src/Relationships/Many.php","position":152,"original_position":152,"commit_id":"c58c8f210a425a91a8793b0a1ab4c9f66d2c6bab","original_commit_id":"c58c8f210a425a91a8793b0a1ab4c9f66d2c6bab","user":{"login":"ZZromanZZ","id":99749,"avatar_url":"https://avatars.githubusercontent.com/u/99749?v=3","gravatar_id":"","url":"https://api.github.com/users/ZZromanZZ","html_url":"https://github.com/ZZromanZZ","followers_url":"https://api.github.com/users/ZZromanZZ/followers","following_url":"https://api.github.com/users/ZZromanZZ/following{/other_user}","gists_url":"https://api.github.com/users/ZZromanZZ/gists{/gist_id}","starred_url":"https://api.github.com/users/ZZromanZZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZZromanZZ/subscriptions","organizations_url":"https://api.github.com/users/ZZromanZZ/orgs","repos_url":"https://api.github.com/users/ZZromanZZ/repos","events_url":"https://api.github.com/users/ZZromanZZ/events{/privacy}","received_events_url":"https://api.github.com/users/ZZromanZZ/received_events","type":"User","site_admin":false},"body":"Missing line end at the end of file","created_at":"2015-09-19T10:53:28Z","updated_at":"2015-09-19T10:53:28Z","html_url":"https://github.com/obophp/obo/pull/179#discussion_r39918682","pull_request_url":"https://api.github.com/repos/obophp/obo/pulls/179","_links":{"self":{"href":"https://api.github.com/repos/obophp/obo/pulls/comments/39918682"},"html":{"href":"https://github.com/obophp/obo/pull/179#discussion_r39918682"},"pull_request":{"href":"https://api.github.com/repos/obophp/obo/pulls/179"}}},"pull_request":{"url":"https://api.github.com/repos/obophp/obo/pulls/179","id":45276436,"html_url":"https://github.com/obophp/obo/pull/179","diff_url":"https://github.com/obophp/obo/pull/179.diff","patch_url":"https://github.com/obophp/obo/pull/179.patch","issue_url":"https://api.github.com/repos/obophp/obo/issues/179","number":179,"state":"open","locked":false,"title":"Refactored entities collection and many relationship","user":{"login":"hAdamm","id":2187723,"avatar_url":"https://avatars.githubusercontent.com/u/2187723?v=3","gravatar_id":"","url":"https://api.github.com/users/hAdamm","html_url":"https://github.com/hAdamm","followers_url":"https://api.github.com/users/hAdamm/followers","following_url":"https://api.github.com/users/hAdamm/following{/other_user}","gists_url":"https://api.github.com/users/hAdamm/gists{/gist_id}","starred_url":"https://api.github.com/users/hAdamm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hAdamm/subscriptions","organizations_url":"https://api.github.com/users/hAdamm/orgs","repos_url":"https://api.github.com/users/hAdamm/repos","events_url":"https://api.github.com/users/hAdamm/events{/privacy}","received_events_url":"https://api.github.com/users/hAdamm/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-17T10:51:48Z","updated_at":"2015-09-19T10:53:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15f5c41e7ff3ffde375e500655fd5321b12c896f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/obophp/obo/pulls/179/commits","review_comments_url":"https://api.github.com/repos/obophp/obo/pulls/179/comments","review_comment_url":"https://api.github.com/repos/obophp/obo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/obophp/obo/issues/179/comments","statuses_url":"https://api.github.com/repos/obophp/obo/statuses/c58c8f210a425a91a8793b0a1ab4c9f66d2c6bab","head":{"label":"hAdamm:as-development","ref":"as-development","sha":"c58c8f210a425a91a8793b0a1ab4c9f66d2c6bab","user":{"login":"hAdamm","id":2187723,"avatar_url":"https://avatars.githubusercontent.com/u/2187723?v=3","gravatar_id":"","url":"https://api.github.com/users/hAdamm","html_url":"https://github.com/hAdamm","followers_url":"https://api.github.com/users/hAdamm/followers","following_url":"https://api.github.com/users/hAdamm/following{/other_user}","gists_url":"https://api.github.com/users/hAdamm/gists{/gist_id}","starred_url":"https://api.github.com/users/hAdamm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hAdamm/subscriptions","organizations_url":"https://api.github.com/users/hAdamm/orgs","repos_url":"https://api.github.com/users/hAdamm/repos","events_url":"https://api.github.com/users/hAdamm/events{/privacy}","received_events_url":"https://api.github.com/users/hAdamm/received_events","type":"User","site_admin":false},"repo":{"id":17705689,"name":"obo","full_name":"hAdamm/obo","owner":{"login":"hAdamm","id":2187723,"avatar_url":"https://avatars.githubusercontent.com/u/2187723?v=3","gravatar_id":"","url":"https://api.github.com/users/hAdamm","html_url":"https://github.com/hAdamm","followers_url":"https://api.github.com/users/hAdamm/followers","following_url":"https://api.github.com/users/hAdamm/following{/other_user}","gists_url":"https://api.github.com/users/hAdamm/gists{/gist_id}","starred_url":"https://api.github.com/users/hAdamm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hAdamm/subscriptions","organizations_url":"https://api.github.com/users/hAdamm/orgs","repos_url":"https://api.github.com/users/hAdamm/repos","events_url":"https://api.github.com/users/hAdamm/events{/privacy}","received_events_url":"https://api.github.com/users/hAdamm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hAdamm/obo","description":"Event driven ORM library","fork":true,"url":"https://api.github.com/repos/hAdamm/obo","forks_url":"https://api.github.com/repos/hAdamm/obo/forks","keys_url":"https://api.github.com/repos/hAdamm/obo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hAdamm/obo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hAdamm/obo/teams","hooks_url":"https://api.github.com/repos/hAdamm/obo/hooks","issue_events_url":"https://api.github.com/repos/hAdamm/obo/issues/events{/number}","events_url":"https://api.github.com/repos/hAdamm/obo/events","assignees_url":"https://api.github.com/repos/hAdamm/obo/assignees{/user}","branches_url":"https://api.github.com/repos/hAdamm/obo/branches{/branch}","tags_url":"https://api.github.com/repos/hAdamm/obo/tags","blobs_url":"https://api.github.com/repos/hAdamm/obo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hAdamm/obo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hAdamm/obo/git/refs{/sha}","trees_url":"https://api.github.com/repos/hAdamm/obo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hAdamm/obo/statuses/{sha}","languages_url":"https://api.github.com/repos/hAdamm/obo/languages","stargazers_url":"https://api.github.com/repos/hAdamm/obo/stargazers","contributors_url":"https://api.github.com/repos/hAdamm/obo/contributors","subscribers_url":"https://api.github.com/repos/hAdamm/obo/subscribers","subscription_url":"https://api.github.com/repos/hAdamm/obo/subscription","commits_url":"https://api.github.com/repos/hAdamm/obo/commits{/sha}","git_commits_url":"https://api.github.com/repos/hAdamm/obo/git/commits{/sha}","comments_url":"https://api.github.com/repos/hAdamm/obo/comments{/number}","issue_comment_url":"https://api.github.com/repos/hAdamm/obo/issues/comments{/number}","contents_url":"https://api.github.com/repos/hAdamm/obo/contents/{+path}","compare_url":"https://api.github.com/repos/hAdamm/obo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hAdamm/obo/merges","archive_url":"https://api.github.com/repos/hAdamm/obo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hAdamm/obo/downloads","issues_url":"https://api.github.com/repos/hAdamm/obo/issues{/number}","pulls_url":"https://api.github.com/repos/hAdamm/obo/pulls{/number}","milestones_url":"https://api.github.com/repos/hAdamm/obo/milestones{/number}","notifications_url":"https://api.github.com/repos/hAdamm/obo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hAdamm/obo/labels{/name}","releases_url":"https://api.github.com/repos/hAdamm/obo/releases{/id}","created_at":"2014-03-13T10:09:56Z","updated_at":"2014-07-23T04:57:34Z","pushed_at":"2015-09-17T10:10:50Z","git_url":"git://github.com/hAdamm/obo.git","ssh_url":"git@github.com:hAdamm/obo.git","clone_url":"https://github.com/hAdamm/obo.git","svn_url":"https://github.com/hAdamm/obo","homepage":null,"size":918,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"obophp:master","ref":"master","sha":"164f05ee90f24d8a54b3c221b6e03a8e9ad0070f","user":{"login":"obophp","id":6529854,"avatar_url":"https://avatars.githubusercontent.com/u/6529854?v=3","gravatar_id":"","url":"https://api.github.com/users/obophp","html_url":"https://github.com/obophp","followers_url":"https://api.github.com/users/obophp/followers","following_url":"https://api.github.com/users/obophp/following{/other_user}","gists_url":"https://api.github.com/users/obophp/gists{/gist_id}","starred_url":"https://api.github.com/users/obophp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obophp/subscriptions","organizations_url":"https://api.github.com/users/obophp/orgs","repos_url":"https://api.github.com/users/obophp/repos","events_url":"https://api.github.com/users/obophp/events{/privacy}","received_events_url":"https://api.github.com/users/obophp/received_events","type":"User","site_admin":false},"repo":{"id":16329200,"name":"obo","full_name":"obophp/obo","owner":{"login":"obophp","id":6529854,"avatar_url":"https://avatars.githubusercontent.com/u/6529854?v=3","gravatar_id":"","url":"https://api.github.com/users/obophp","html_url":"https://github.com/obophp","followers_url":"https://api.github.com/users/obophp/followers","following_url":"https://api.github.com/users/obophp/following{/other_user}","gists_url":"https://api.github.com/users/obophp/gists{/gist_id}","starred_url":"https://api.github.com/users/obophp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obophp/subscriptions","organizations_url":"https://api.github.com/users/obophp/orgs","repos_url":"https://api.github.com/users/obophp/repos","events_url":"https://api.github.com/users/obophp/events{/privacy}","received_events_url":"https://api.github.com/users/obophp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/obophp/obo","description":"Event driven ORM library","fork":false,"url":"https://api.github.com/repos/obophp/obo","forks_url":"https://api.github.com/repos/obophp/obo/forks","keys_url":"https://api.github.com/repos/obophp/obo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/obophp/obo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/obophp/obo/teams","hooks_url":"https://api.github.com/repos/obophp/obo/hooks","issue_events_url":"https://api.github.com/repos/obophp/obo/issues/events{/number}","events_url":"https://api.github.com/repos/obophp/obo/events","assignees_url":"https://api.github.com/repos/obophp/obo/assignees{/user}","branches_url":"https://api.github.com/repos/obophp/obo/branches{/branch}","tags_url":"https://api.github.com/repos/obophp/obo/tags","blobs_url":"https://api.github.com/repos/obophp/obo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/obophp/obo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/obophp/obo/git/refs{/sha}","trees_url":"https://api.github.com/repos/obophp/obo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/obophp/obo/statuses/{sha}","languages_url":"https://api.github.com/repos/obophp/obo/languages","stargazers_url":"https://api.github.com/repos/obophp/obo/stargazers","contributors_url":"https://api.github.com/repos/obophp/obo/contributors","subscribers_url":"https://api.github.com/repos/obophp/obo/subscribers","subscription_url":"https://api.github.com/repos/obophp/obo/subscription","commits_url":"https://api.github.com/repos/obophp/obo/commits{/sha}","git_commits_url":"https://api.github.com/repos/obophp/obo/git/commits{/sha}","comments_url":"https://api.github.com/repos/obophp/obo/comments{/number}","issue_comment_url":"https://api.github.com/repos/obophp/obo/issues/comments{/number}","contents_url":"https://api.github.com/repos/obophp/obo/contents/{+path}","compare_url":"https://api.github.com/repos/obophp/obo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/obophp/obo/merges","archive_url":"https://api.github.com/repos/obophp/obo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/obophp/obo/downloads","issues_url":"https://api.github.com/repos/obophp/obo/issues{/number}","pulls_url":"https://api.github.com/repos/obophp/obo/pulls{/number}","milestones_url":"https://api.github.com/repos/obophp/obo/milestones{/number}","notifications_url":"https://api.github.com/repos/obophp/obo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/obophp/obo/labels{/name}","releases_url":"https://api.github.com/repos/obophp/obo/releases{/id}","created_at":"2014-01-28T23:05:50Z","updated_at":"2015-04-03T19:25:07Z","pushed_at":"2015-09-17T10:51:48Z","git_url":"git://github.com/obophp/obo.git","ssh_url":"git@github.com:obophp/obo.git","clone_url":"https://github.com/obophp/obo.git","svn_url":"https://github.com/obophp/obo","homepage":null,"size":1722,"stargazers_count":10,"watchers_count":10,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":8,"mirror_url":null,"open_issues_count":4,"forks":8,"open_issues":4,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/obophp/obo/pulls/179"},"html":{"href":"https://github.com/obophp/obo/pull/179"},"issue":{"href":"https://api.github.com/repos/obophp/obo/issues/179"},"comments":{"href":"https://api.github.com/repos/obophp/obo/issues/179/comments"},"review_comments":{"href":"https://api.github.com/repos/obophp/obo/pulls/179/comments"},"review_comment":{"href":"https://api.github.com/repos/obophp/obo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/obophp/obo/pulls/179/commits"},"statuses":{"href":"https://api.github.com/repos/obophp/obo/statuses/c58c8f210a425a91a8793b0a1ab4c9f66d2c6bab"}}}}