{"action":"created","issue":{"url":"https://api.github.com/repos/iamfat/qf/issues/17","labels_url":"https://api.github.com/repos/iamfat/qf/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/iamfat/qf/issues/17/comments","events_url":"https://api.github.com/repos/iamfat/qf/issues/17/events","html_url":"https://github.com/iamfat/qf/issues/17","id":52067023,"number":17,"title":"Q($selector)->append($object) append只可append一个对象","user":{"login":"stenote","id":1109648,"avatar_url":"https://avatars.githubusercontent.com/u/1109648?v=3","gravatar_id":"","url":"https://api.github.com/users/stenote","html_url":"https://github.com/stenote","followers_url":"https://api.github.com/users/stenote/followers","following_url":"https://api.github.com/users/stenote/following{/other_user}","gists_url":"https://api.github.com/users/stenote/gists{/gist_id}","starred_url":"https://api.github.com/users/stenote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stenote/subscriptions","organizations_url":"https://api.github.com/users/stenote/orgs","repos_url":"https://api.github.com/users/stenote/repos","events_url":"https://api.github.com/users/stenote/events{/privacy}","received_events_url":"https://api.github.com/users/stenote/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-12-16T02:40:29Z","updated_at":"2015-06-10T05:57:53Z","closed_at":"2015-06-10T05:57:53Z","body":"```\r\n\tfunction append($object){\r\n\t\t$this->check_query();\r\n\r\n\t\tif (is_array($object)) {\r\n\t\t\t$object = O($this->name, $object, TRUE);\r\n\t\t}\r\n\t\telseif ($object instanceof ORM_Iterator) {\r\n\t\t\t$object = $object->objects[$object->current_id];\r\n\t\t}\r\n\r\n\t\tif ($object instanceof ORM_Model && $object->id) {\r\n\t\t\t$this->objects[$object->id] = $object;\r\n\t\t}\r\n\r\n\t\t$this->count = $this->length = count($this->objects);\r\n\t\treturn $this;\r\n\t}\r\n```\r\n\r\n如上，如果传入object为ORM_Iterator，则只会获取第一个ORM_Iterator结果进来。\r\n\r\n考虑修正方法如下：\r\n\r\n```\r\n    public function append($objects) {\r\n\r\n        $this->check_query();\r\n\r\n        if (is_array($objects) || ($objects instanceof ORM_Iterator)) {\r\n            foreach($objects as $object) {\r\n                $this->objects[$object->id] = $object;\r\n            }\r\n        }\r\n        elseif ($objects instanceof ORM_Model && $objects->id) {\r\n            $this->objects[$object->id] = $object;\r\n        }\r\n\r\n        $this->count = $this->length = count($this->objects);\r\n\r\n        return $this;\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/iamfat/qf/issues/comments/110602262","html_url":"https://github.com/iamfat/qf/issues/17#issuecomment-110602262","issue_url":"https://api.github.com/repos/iamfat/qf/issues/17","id":110602262,"user":{"login":"stenote","id":1109648,"avatar_url":"https://avatars.githubusercontent.com/u/1109648?v=3","gravatar_id":"","url":"https://api.github.com/users/stenote","html_url":"https://github.com/stenote","followers_url":"https://api.github.com/users/stenote/followers","following_url":"https://api.github.com/users/stenote/following{/other_user}","gists_url":"https://api.github.com/users/stenote/gists{/gist_id}","starred_url":"https://api.github.com/users/stenote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stenote/subscriptions","organizations_url":"https://api.github.com/users/stenote/orgs","repos_url":"https://api.github.com/users/stenote/repos","events_url":"https://api.github.com/users/stenote/events{/privacy}","received_events_url":"https://api.github.com/users/stenote/received_events","type":"User","site_admin":false},"created_at":"2015-06-10T05:57:53Z","updated_at":"2015-06-10T05:57:53Z","body":"Q 后的结果本来就是进行合集。合集可以考虑 merge 另外一个合集，或者 append 一个对象。\r\n可以理解为 array_merge (+) 和 array_push 的区别。\r\n\r\n此处 Q()->append() 就是 array_push ，而不是 merge"}}