{"action":"created","issue":{"url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/282","repository_url":"https://api.github.com/repos/yapstudios/YapDatabase","labels_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/282/labels{/name}","comments_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/282/comments","events_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/282/events","html_url":"https://github.com/yapstudios/YapDatabase/issues/282","id":133232537,"number":282,"title":"Grouping a database view on a non-model value","user":{"login":"accatyyc","id":1607453,"avatar_url":"https://avatars.githubusercontent.com/u/1607453?v=3","gravatar_id":"","url":"https://api.github.com/users/accatyyc","html_url":"https://github.com/accatyyc","followers_url":"https://api.github.com/users/accatyyc/followers","following_url":"https://api.github.com/users/accatyyc/following{/other_user}","gists_url":"https://api.github.com/users/accatyyc/gists{/gist_id}","starred_url":"https://api.github.com/users/accatyyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/accatyyc/subscriptions","organizations_url":"https://api.github.com/users/accatyyc/orgs","repos_url":"https://api.github.com/users/accatyyc/repos","events_url":"https://api.github.com/users/accatyyc/events{/privacy}","received_events_url":"https://api.github.com/users/accatyyc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-12T12:47:07Z","updated_at":"2016-02-18T06:48:50Z","closed_at":null,"body":"This is not exactly an issue, but more a question on the recommended way to achieve the following:\r\n\r\nFor example, we have a `YapDatabaseView` that should contain all objects in `collection` with a specific sorting and grouping. The first group, called `recent_items` should contain all items that were created after a specific a date, say `one hour ago`. \r\n\r\nNow obviously, `one hour ago` is a dynamic value. Every time it changes, the grouping block needs to be run again to make sure only the recent items are in the first group.\r\n\r\n`one hour ago` is also not stored in the database, so there's no automatic way for the view to actually know that the grouping should have been updated.\r\n\r\nCurrently, we have considered some ways ways of doing this:\r\n\r\n## 1. Unregister/register the view\r\nThis forces the grouping to run again. It does however, force it to run on _all_ objects in the database not covered in the view whitelist. It works, but it doesn't feel efficient.\r\n\r\n## 2. Touching all the objects in the collection\r\nAnother way is to enumerate all objects in the view (or the collection) and just touch them. This allows the view to pick up any potential objects that should have changed groups. It also doesn't feel perfect, since there is actually nothing changing in any of the objects (and still, thousands of objects may not need to be regrouped).\r\n\r\n## 3. Register grouping/sorting with a new version\r\nA third way would be to use ` (void)setGrouping:(YapDatabaseViewGrouping *)grouping sorting:(YapDatabaseViewSorting *)sorting versionTag:(nullable NSString *)versionTag` in `YapDatabseViewTransaction` to update the grouping/sorting. This would force it to sort again, but we feel that it's essentially the same thing as unregistering and re-registering the view.\r\n\r\nIs there any recommended/better/easier/cleverer way to achieve this?"},"comment":{"url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/comments/185568416","html_url":"https://github.com/yapstudios/YapDatabase/issues/282#issuecomment-185568416","issue_url":"https://api.github.com/repos/yapstudios/YapDatabase/issues/282","id":185568416,"user":{"login":"accatyyc","id":1607453,"avatar_url":"https://avatars.githubusercontent.com/u/1607453?v=3","gravatar_id":"","url":"https://api.github.com/users/accatyyc","html_url":"https://github.com/accatyyc","followers_url":"https://api.github.com/users/accatyyc/followers","following_url":"https://api.github.com/users/accatyyc/following{/other_user}","gists_url":"https://api.github.com/users/accatyyc/gists{/gist_id}","starred_url":"https://api.github.com/users/accatyyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/accatyyc/subscriptions","organizations_url":"https://api.github.com/users/accatyyc/orgs","repos_url":"https://api.github.com/users/accatyyc/repos","events_url":"https://api.github.com/users/accatyyc/events{/privacy}","received_events_url":"https://api.github.com/users/accatyyc/received_events","type":"User","site_admin":false},"created_at":"2016-02-18T06:48:50Z","updated_at":"2016-02-18T06:48:50Z","body":"Thanks! Will take a look at actions!"}}