{"action":"created","comment":{"url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/comments/35417599","id":35417599,"diff_hunk":"@@ -28,6 +28,7 @@ def initialize(collection)\n         # @api private\n         # @since 0.1.0\n         def to_record(entity)\n+          @collection.type.to_record(entity)","path":"lib/lotus/model/mapping/coercer.rb","position":4,"original_position":4,"commit_id":"c28fdfed0c5f68657e622da323f981b2d17d33d0","original_commit_id":"c28fdfed0c5f68657e622da323f981b2d17d33d0","user":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"body":"The idea was that an entity is \"just\" a composite type with an identifier. While it's not (yet) implemented that way the behaviour should be mostly the same whether you compose/decompose an entity or a composite type.\r\nAs implemented currently it does not make much sense to move the logic into it's own type, i agree.","created_at":"2015-07-24T12:31:07Z","updated_at":"2015-07-24T12:31:07Z","html_url":"https://github.com/pascalbetz/lotus-model/pull/1#discussion_r35417599","pull_request_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/comments/35417599"},"html":{"href":"https://github.com/pascalbetz/lotus-model/pull/1#discussion_r35417599"},"pull_request":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1","id":40008842,"html_url":"https://github.com/pascalbetz/lotus-model/pull/1","diff_url":"https://github.com/pascalbetz/lotus-model/pull/1.diff","patch_url":"https://github.com/pascalbetz/lotus-model/pull/1.patch","issue_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/1","number":1,"state":"open","locked":false,"title":"Mapped types","user":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"body":"## Change the way lotus model internally maps entities\r\n\r\nI played around with lotus-model and noticed that there are several mapping\r\nrelated Issues on github. I think lots of those issues can not be solved properly\r\nwithout changing how lotus-model does the mapping. I had an idea how this can be done\r\nand started coding.\r\n\r\n## Why?\r\n\r\nAllows for:\r\n\r\n* default values (see fixtures.rb: default_value)\r\n* Single Table Inheritance (See SpecializedArticle)\r\n* Nested attributes (See Use/Address/City)\r\n* Arbitrary depths of nesting with attributes (tested to 2 levels only though)\r\n* Custom Types (see ComplexNumber + ComplexNumberType)\r\n\r\nProvides a base to solve #36, #183, #136 (on lotus model)\r\n\r\n## General\r\n\r\nEach attribute that is mapped is represented by a type. A type is composed of the attribute name, mapped name and ruby class it maps. There are _atoms_ (if you look at an object as a graph: leaf nodes) for stuff like Integers, Dates, ... and _composites_. \r\nBecause i wanted to allow for nested attributes, those types can also be nested. There are some built in types (everything that can be coerced by Kernel) and custom types can be added and used.\r\n\r\nA type can do two things:\r\n\r\n* convert from record (a hash) to the mapped ruby class\r\n* convert from the mapped ruby class to a record\r\n\r\n## Caveat Emptor\r\n\r\nThis is a first take, basically a proof of concept. Lots of work in progress and\r\nprobably more questions than before. Code is unfinished and especially the type\r\nstructure seems to be a candidate for cleaning up (lots of inheritance) + I broke\r\nquite some tests (or just commented them).\r\n\r\nBut it's working and I first want to get some feedback and see if this is wanted at all.\r\n\r\n\r\nStuff to look at, besides cleaning up the code:\r\n\r\n* Currently from/to_record does not have the same interface, kind of looks wrong\r\n* Performance. How does it compare to the precompiled version\r\n* \r\n","created_at":"2015-07-15T10:37:02Z","updated_at":"2015-07-24T12:31:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"671f1718e22c750fd0dfe8542516f13b592bc1d6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1/commits","review_comments_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1/comments","review_comment_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/1/comments","statuses_url":"https://api.github.com/repos/pascalbetz/lotus-model/statuses/c28fdfed0c5f68657e622da323f981b2d17d33d0","head":{"label":"pascalbetz:mapped-types","ref":"mapped-types","sha":"c28fdfed0c5f68657e622da323f981b2d17d33d0","user":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"repo":{"id":38829646,"name":"lotus-model","full_name":"pascalbetz/lotus-model","owner":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pascalbetz/lotus-model","description":"A persistence framework with entities, repositories, data mapper and query objects","fork":true,"url":"https://api.github.com/repos/pascalbetz/lotus-model","forks_url":"https://api.github.com/repos/pascalbetz/lotus-model/forks","keys_url":"https://api.github.com/repos/pascalbetz/lotus-model/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pascalbetz/lotus-model/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pascalbetz/lotus-model/teams","hooks_url":"https://api.github.com/repos/pascalbetz/lotus-model/hooks","issue_events_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/events{/number}","events_url":"https://api.github.com/repos/pascalbetz/lotus-model/events","assignees_url":"https://api.github.com/repos/pascalbetz/lotus-model/assignees{/user}","branches_url":"https://api.github.com/repos/pascalbetz/lotus-model/branches{/branch}","tags_url":"https://api.github.com/repos/pascalbetz/lotus-model/tags","blobs_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/refs{/sha}","trees_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pascalbetz/lotus-model/statuses/{sha}","languages_url":"https://api.github.com/repos/pascalbetz/lotus-model/languages","stargazers_url":"https://api.github.com/repos/pascalbetz/lotus-model/stargazers","contributors_url":"https://api.github.com/repos/pascalbetz/lotus-model/contributors","subscribers_url":"https://api.github.com/repos/pascalbetz/lotus-model/subscribers","subscription_url":"https://api.github.com/repos/pascalbetz/lotus-model/subscription","commits_url":"https://api.github.com/repos/pascalbetz/lotus-model/commits{/sha}","git_commits_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/commits{/sha}","comments_url":"https://api.github.com/repos/pascalbetz/lotus-model/comments{/number}","issue_comment_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/comments{/number}","contents_url":"https://api.github.com/repos/pascalbetz/lotus-model/contents/{+path}","compare_url":"https://api.github.com/repos/pascalbetz/lotus-model/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pascalbetz/lotus-model/merges","archive_url":"https://api.github.com/repos/pascalbetz/lotus-model/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pascalbetz/lotus-model/downloads","issues_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues{/number}","pulls_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls{/number}","milestones_url":"https://api.github.com/repos/pascalbetz/lotus-model/milestones{/number}","notifications_url":"https://api.github.com/repos/pascalbetz/lotus-model/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pascalbetz/lotus-model/labels{/name}","releases_url":"https://api.github.com/repos/pascalbetz/lotus-model/releases{/id}","created_at":"2015-07-09T15:43:23Z","updated_at":"2015-07-09T15:43:59Z","pushed_at":"2015-07-20T09:37:14Z","git_url":"git://github.com/pascalbetz/lotus-model.git","ssh_url":"git@github.com:pascalbetz/lotus-model.git","clone_url":"https://github.com/pascalbetz/lotus-model.git","svn_url":"https://github.com/pascalbetz/lotus-model","homepage":"","size":856,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"pascalbetz:master","ref":"master","sha":"c28cb0e877051f3d4a7409a071157cd3d498d1c2","user":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"repo":{"id":38829646,"name":"lotus-model","full_name":"pascalbetz/lotus-model","owner":{"login":"pascalbetz","id":16653,"avatar_url":"https://avatars.githubusercontent.com/u/16653?v=3","gravatar_id":"","url":"https://api.github.com/users/pascalbetz","html_url":"https://github.com/pascalbetz","followers_url":"https://api.github.com/users/pascalbetz/followers","following_url":"https://api.github.com/users/pascalbetz/following{/other_user}","gists_url":"https://api.github.com/users/pascalbetz/gists{/gist_id}","starred_url":"https://api.github.com/users/pascalbetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pascalbetz/subscriptions","organizations_url":"https://api.github.com/users/pascalbetz/orgs","repos_url":"https://api.github.com/users/pascalbetz/repos","events_url":"https://api.github.com/users/pascalbetz/events{/privacy}","received_events_url":"https://api.github.com/users/pascalbetz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pascalbetz/lotus-model","description":"A persistence framework with entities, repositories, data mapper and query objects","fork":true,"url":"https://api.github.com/repos/pascalbetz/lotus-model","forks_url":"https://api.github.com/repos/pascalbetz/lotus-model/forks","keys_url":"https://api.github.com/repos/pascalbetz/lotus-model/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pascalbetz/lotus-model/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pascalbetz/lotus-model/teams","hooks_url":"https://api.github.com/repos/pascalbetz/lotus-model/hooks","issue_events_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/events{/number}","events_url":"https://api.github.com/repos/pascalbetz/lotus-model/events","assignees_url":"https://api.github.com/repos/pascalbetz/lotus-model/assignees{/user}","branches_url":"https://api.github.com/repos/pascalbetz/lotus-model/branches{/branch}","tags_url":"https://api.github.com/repos/pascalbetz/lotus-model/tags","blobs_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/refs{/sha}","trees_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pascalbetz/lotus-model/statuses/{sha}","languages_url":"https://api.github.com/repos/pascalbetz/lotus-model/languages","stargazers_url":"https://api.github.com/repos/pascalbetz/lotus-model/stargazers","contributors_url":"https://api.github.com/repos/pascalbetz/lotus-model/contributors","subscribers_url":"https://api.github.com/repos/pascalbetz/lotus-model/subscribers","subscription_url":"https://api.github.com/repos/pascalbetz/lotus-model/subscription","commits_url":"https://api.github.com/repos/pascalbetz/lotus-model/commits{/sha}","git_commits_url":"https://api.github.com/repos/pascalbetz/lotus-model/git/commits{/sha}","comments_url":"https://api.github.com/repos/pascalbetz/lotus-model/comments{/number}","issue_comment_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues/comments{/number}","contents_url":"https://api.github.com/repos/pascalbetz/lotus-model/contents/{+path}","compare_url":"https://api.github.com/repos/pascalbetz/lotus-model/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pascalbetz/lotus-model/merges","archive_url":"https://api.github.com/repos/pascalbetz/lotus-model/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pascalbetz/lotus-model/downloads","issues_url":"https://api.github.com/repos/pascalbetz/lotus-model/issues{/number}","pulls_url":"https://api.github.com/repos/pascalbetz/lotus-model/pulls{/number}","milestones_url":"https://api.github.com/repos/pascalbetz/lotus-model/milestones{/number}","notifications_url":"https://api.github.com/repos/pascalbetz/lotus-model/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pascalbetz/lotus-model/labels{/name}","releases_url":"https://api.github.com/repos/pascalbetz/lotus-model/releases{/id}","created_at":"2015-07-09T15:43:23Z","updated_at":"2015-07-09T15:43:59Z","pushed_at":"2015-07-20T09:37:14Z","git_url":"git://github.com/pascalbetz/lotus-model.git","ssh_url":"git@github.com:pascalbetz/lotus-model.git","clone_url":"https://github.com/pascalbetz/lotus-model.git","svn_url":"https://github.com/pascalbetz/lotus-model","homepage":"","size":856,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1"},"html":{"href":"https://github.com/pascalbetz/lotus-model/pull/1"},"issue":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/issues/1"},"comments":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/pascalbetz/lotus-model/statuses/c28fdfed0c5f68657e622da323f981b2d17d33d0"}}}}