{"action":"closed","number":48,"pull_request":{"url":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48","id":33244385,"html_url":"https://github.com/bcosca/fatfree-core/pull/48","diff_url":"https://github.com/bcosca/fatfree-core/pull/48.diff","patch_url":"https://github.com/bcosca/fatfree-core/pull/48.patch","issue_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/48","number":48,"state":"closed","locked":false,"title":"keep reference to Jig table, bcosca/fatfree#758","user":{"login":"ikkez","id":1177647,"avatar_url":"https://avatars.githubusercontent.com/u/1177647?v=3","gravatar_id":"","url":"https://api.github.com/users/ikkez","html_url":"https://github.com/ikkez","followers_url":"https://api.github.com/users/ikkez/followers","following_url":"https://api.github.com/users/ikkez/following{/other_user}","gists_url":"https://api.github.com/users/ikkez/gists{/gist_id}","starred_url":"https://api.github.com/users/ikkez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikkez/subscriptions","organizations_url":"https://api.github.com/users/ikkez/orgs","repos_url":"https://api.github.com/users/ikkez/repos","events_url":"https://api.github.com/users/ikkez/events{/privacy}","received_events_url":"https://api.github.com/users/ikkez/received_events","type":"User","site_admin":false},"body":"This approach intends to fix bcosca/fatfree#758. The problem in this issue was that updating the `$self` mapper within an event handler was ignored, since its document data was already mapped to the db entry before the event handler is triggered.\r\nThis was not the only issue here. When you try to invoke a new mapper or alter the same jig table of a mapper within an event handler, the changes made to the table array didn't had any effect, because the table `$data` was already read from the db file and writing it down again would overwrite any changes made in an event handler. Instead of reading the whole `$data` once more after calling the event to obtain the changes, I thought it would be smarter to keep a reference to the loaded table data. This way any changes to the table data are consistent.\r\n\r\nhere a little test. it's a generic way to add version-control to a mapper, which shows the issue (only store the last 3 records as backup)\r\n```php\r\n$f3->route('GET /jigtest', function($f3) {\r\n    $f3->set('DB', new \\DB\\Jig('data/'));\r\n    $mapper = new \\DB\\Jig\\Mapper($f3['DB'],'test');\r\n    $mapper->beforeupdate(function($self,$pkeys){\r\n        $backup = new $self(\\Base::instance()->get('DB'),'test');\r\n        $backup->load(array('@_id = ?',$pkeys['_id']));\r\n        $backup->copyto('backup');\r\n        $backup->reset();\r\n        $backup->copyfrom('backup');\r\n        $backup->save();\r\n        $self->version++;\r\n        $self->erase(array('@version < ?',$self->version-3));\r\n    });\r\n    $mapper->beforeinsert(function($self,$pkeys){\r\n        $self->version = 1;\r\n    });\r\n\r\n    $mapper->title = 'ABC';\r\n    $mapper->text = \\Web::instance()->filler(1,rand(3,8),false);\r\n    $mapper->save();\r\n\r\n    for($i=0;$i<10;$i++) {\r\n      $mapper->reset();\r\n      $mapper->load(array('@title = ? ','ABC'));\r\n      $mapper->text = \\Web::instance()->filler(1,rand(3,8),false);\r\n      $mapper->save();\r\n    }\r\n});\r\n```","created_at":"2015-04-14T10:26:25Z","updated_at":"2015-04-16T06:16:31Z","closed_at":"2015-04-16T06:16:31Z","merged_at":"2015-04-16T06:16:31Z","merge_commit_sha":"8074af883c08e434af00810f8061ead134c30ef2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48/commits","review_comments_url":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48/comments","review_comment_url":"https://api.github.com/repos/bcosca/fatfree-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/48/comments","statuses_url":"https://api.github.com/repos/bcosca/fatfree-core/statuses/fc076dc17ef2aa32a682efc882c38ad19ba58e57","head":{"label":"ikkez:jig_event_fixes","ref":"jig_event_fixes","sha":"fc076dc17ef2aa32a682efc882c38ad19ba58e57","user":{"login":"ikkez","id":1177647,"avatar_url":"https://avatars.githubusercontent.com/u/1177647?v=3","gravatar_id":"","url":"https://api.github.com/users/ikkez","html_url":"https://github.com/ikkez","followers_url":"https://api.github.com/users/ikkez/followers","following_url":"https://api.github.com/users/ikkez/following{/other_user}","gists_url":"https://api.github.com/users/ikkez/gists{/gist_id}","starred_url":"https://api.github.com/users/ikkez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikkez/subscriptions","organizations_url":"https://api.github.com/users/ikkez/orgs","repos_url":"https://api.github.com/users/ikkez/repos","events_url":"https://api.github.com/users/ikkez/events{/privacy}","received_events_url":"https://api.github.com/users/ikkez/received_events","type":"User","site_admin":false},"repo":{"id":26753953,"name":"fatfree-core","full_name":"ikkez/fatfree-core","owner":{"login":"ikkez","id":1177647,"avatar_url":"https://avatars.githubusercontent.com/u/1177647?v=3","gravatar_id":"","url":"https://api.github.com/users/ikkez","html_url":"https://github.com/ikkez","followers_url":"https://api.github.com/users/ikkez/followers","following_url":"https://api.github.com/users/ikkez/following{/other_user}","gists_url":"https://api.github.com/users/ikkez/gists{/gist_id}","starred_url":"https://api.github.com/users/ikkez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikkez/subscriptions","organizations_url":"https://api.github.com/users/ikkez/orgs","repos_url":"https://api.github.com/users/ikkez/repos","events_url":"https://api.github.com/users/ikkez/events{/privacy}","received_events_url":"https://api.github.com/users/ikkez/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ikkez/fatfree-core","description":"Fat-Free Framework core library","fork":true,"url":"https://api.github.com/repos/ikkez/fatfree-core","forks_url":"https://api.github.com/repos/ikkez/fatfree-core/forks","keys_url":"https://api.github.com/repos/ikkez/fatfree-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ikkez/fatfree-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ikkez/fatfree-core/teams","hooks_url":"https://api.github.com/repos/ikkez/fatfree-core/hooks","issue_events_url":"https://api.github.com/repos/ikkez/fatfree-core/issues/events{/number}","events_url":"https://api.github.com/repos/ikkez/fatfree-core/events","assignees_url":"https://api.github.com/repos/ikkez/fatfree-core/assignees{/user}","branches_url":"https://api.github.com/repos/ikkez/fatfree-core/branches{/branch}","tags_url":"https://api.github.com/repos/ikkez/fatfree-core/tags","blobs_url":"https://api.github.com/repos/ikkez/fatfree-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ikkez/fatfree-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ikkez/fatfree-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/ikkez/fatfree-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ikkez/fatfree-core/statuses/{sha}","languages_url":"https://api.github.com/repos/ikkez/fatfree-core/languages","stargazers_url":"https://api.github.com/repos/ikkez/fatfree-core/stargazers","contributors_url":"https://api.github.com/repos/ikkez/fatfree-core/contributors","subscribers_url":"https://api.github.com/repos/ikkez/fatfree-core/subscribers","subscription_url":"https://api.github.com/repos/ikkez/fatfree-core/subscription","commits_url":"https://api.github.com/repos/ikkez/fatfree-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/ikkez/fatfree-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/ikkez/fatfree-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/ikkez/fatfree-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/ikkez/fatfree-core/contents/{+path}","compare_url":"https://api.github.com/repos/ikkez/fatfree-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ikkez/fatfree-core/merges","archive_url":"https://api.github.com/repos/ikkez/fatfree-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ikkez/fatfree-core/downloads","issues_url":"https://api.github.com/repos/ikkez/fatfree-core/issues{/number}","pulls_url":"https://api.github.com/repos/ikkez/fatfree-core/pulls{/number}","milestones_url":"https://api.github.com/repos/ikkez/fatfree-core/milestones{/number}","notifications_url":"https://api.github.com/repos/ikkez/fatfree-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ikkez/fatfree-core/labels{/name}","releases_url":"https://api.github.com/repos/ikkez/fatfree-core/releases{/id}","created_at":"2014-11-17T11:36:27Z","updated_at":"2014-11-25T20:20:12Z","pushed_at":"2015-04-14T07:55:22Z","git_url":"git://github.com/ikkez/fatfree-core.git","ssh_url":"git@github.com:ikkez/fatfree-core.git","clone_url":"https://github.com/ikkez/fatfree-core.git","svn_url":"https://github.com/ikkez/fatfree-core","homepage":null,"size":10901,"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":"bcosca:master","ref":"master","sha":"cb45cf62b18f2f0f2519319a37c0d3487b2a1697","user":{"login":"bcosca","id":199570,"avatar_url":"https://avatars.githubusercontent.com/u/199570?v=3","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false},"repo":{"id":26320119,"name":"fatfree-core","full_name":"bcosca/fatfree-core","owner":{"login":"bcosca","id":199570,"avatar_url":"https://avatars.githubusercontent.com/u/199570?v=3","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bcosca/fatfree-core","description":"Fat-Free Framework core library","fork":false,"url":"https://api.github.com/repos/bcosca/fatfree-core","forks_url":"https://api.github.com/repos/bcosca/fatfree-core/forks","keys_url":"https://api.github.com/repos/bcosca/fatfree-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bcosca/fatfree-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bcosca/fatfree-core/teams","hooks_url":"https://api.github.com/repos/bcosca/fatfree-core/hooks","issue_events_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/events{/number}","events_url":"https://api.github.com/repos/bcosca/fatfree-core/events","assignees_url":"https://api.github.com/repos/bcosca/fatfree-core/assignees{/user}","branches_url":"https://api.github.com/repos/bcosca/fatfree-core/branches{/branch}","tags_url":"https://api.github.com/repos/bcosca/fatfree-core/tags","blobs_url":"https://api.github.com/repos/bcosca/fatfree-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bcosca/fatfree-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bcosca/fatfree-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/bcosca/fatfree-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bcosca/fatfree-core/statuses/{sha}","languages_url":"https://api.github.com/repos/bcosca/fatfree-core/languages","stargazers_url":"https://api.github.com/repos/bcosca/fatfree-core/stargazers","contributors_url":"https://api.github.com/repos/bcosca/fatfree-core/contributors","subscribers_url":"https://api.github.com/repos/bcosca/fatfree-core/subscribers","subscription_url":"https://api.github.com/repos/bcosca/fatfree-core/subscription","commits_url":"https://api.github.com/repos/bcosca/fatfree-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/bcosca/fatfree-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/bcosca/fatfree-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/bcosca/fatfree-core/contents/{+path}","compare_url":"https://api.github.com/repos/bcosca/fatfree-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bcosca/fatfree-core/merges","archive_url":"https://api.github.com/repos/bcosca/fatfree-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bcosca/fatfree-core/downloads","issues_url":"https://api.github.com/repos/bcosca/fatfree-core/issues{/number}","pulls_url":"https://api.github.com/repos/bcosca/fatfree-core/pulls{/number}","milestones_url":"https://api.github.com/repos/bcosca/fatfree-core/milestones{/number}","notifications_url":"https://api.github.com/repos/bcosca/fatfree-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bcosca/fatfree-core/labels{/name}","releases_url":"https://api.github.com/repos/bcosca/fatfree-core/releases{/id}","created_at":"2014-11-07T13:08:48Z","updated_at":"2015-04-13T02:38:18Z","pushed_at":"2015-04-16T06:16:31Z","git_url":"git://github.com/bcosca/fatfree-core.git","ssh_url":"git@github.com:bcosca/fatfree-core.git","clone_url":"https://github.com/bcosca/fatfree-core.git","svn_url":"https://github.com/bcosca/fatfree-core","homepage":null,"size":12047,"stargazers_count":17,"watchers_count":17,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":6,"forks":11,"open_issues":6,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48"},"html":{"href":"https://github.com/bcosca/fatfree-core/pull/48"},"issue":{"href":"https://api.github.com/repos/bcosca/fatfree-core/issues/48"},"comments":{"href":"https://api.github.com/repos/bcosca/fatfree-core/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/bcosca/fatfree-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bcosca/fatfree-core/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/bcosca/fatfree-core/statuses/fc076dc17ef2aa32a682efc882c38ad19ba58e57"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"bcosca","id":199570,"avatar_url":"https://avatars.githubusercontent.com/u/199570?v=3","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false},"comments":0,"review_comments":0,"commits":1,"additions":13,"deletions":11,"changed_files":2}}