{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/607","labels_url":"https://api.github.com/repos/realm/realm-java/issues/607/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/607/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/607/events","html_url":"https://github.com/realm/realm-java/issues/607","id":49878035,"number":607,"title":"Reverse lookup","user":{"login":"tspecht","id":603144,"avatar_url":"https://avatars.githubusercontent.com/u/603144?v=3","gravatar_id":"","url":"https://api.github.com/users/tspecht","html_url":"https://github.com/tspecht","followers_url":"https://api.github.com/users/tspecht/followers","following_url":"https://api.github.com/users/tspecht/following{/other_user}","gists_url":"https://api.github.com/users/tspecht/gists{/gist_id}","starred_url":"https://api.github.com/users/tspecht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tspecht/subscriptions","organizations_url":"https://api.github.com/users/tspecht/orgs","repos_url":"https://api.github.com/users/tspecht/repos","events_url":"https://api.github.com/users/tspecht/events{/privacy}","received_events_url":"https://api.github.com/users/tspecht/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-11-24T11:07:07Z","updated_at":"2015-01-13T07:24:45Z","closed_at":null,"body":"Hi guys,\r\n\r\nI looked at the documentation and found support for linked queries. Is reverse lookup currently possible with the java version of Realm? I'm also using Realm on Cocoa which just added support for reverse lookup and wondered if there is already support for this feature in Java.\r\n\r\nThanks a lot!"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/69705099","html_url":"https://github.com/realm/realm-java/issues/607#issuecomment-69705099","issue_url":"https://api.github.com/repos/realm/realm-java/issues/607","id":69705099,"user":{"login":"cmelchior","id":406066,"avatar_url":"https://avatars.githubusercontent.com/u/406066?v=3","gravatar_id":"","url":"https://api.github.com/users/cmelchior","html_url":"https://github.com/cmelchior","followers_url":"https://api.github.com/users/cmelchior/followers","following_url":"https://api.github.com/users/cmelchior/following{/other_user}","gists_url":"https://api.github.com/users/cmelchior/gists{/gist_id}","starred_url":"https://api.github.com/users/cmelchior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmelchior/subscriptions","organizations_url":"https://api.github.com/users/cmelchior/orgs","repos_url":"https://api.github.com/users/cmelchior/repos","events_url":"https://api.github.com/users/cmelchior/events{/privacy}","received_events_url":"https://api.github.com/users/cmelchior/received_events","type":"User","site_admin":false},"created_at":"2015-01-13T07:24:45Z","updated_at":"2015-01-13T07:24:45Z","body":"This issue has been raised a few times now, so I have begun thinking about implementations:\r\n\r\nCocoa uses the following method: https://github.com/realm/realm-cocoa/blob/master/Realm/RLMObjectBase.mm (linkingObjectsOfClass)\r\n\r\nand is documented here: http://realm.io/docs/cocoa/0.89.2/#inverse-relationships\r\n\r\nI would propose something like this in Java\r\n```\r\npublic class Owner extends RealmObject {\r\n  private RealmList<Dog> dogs;\r\n}\r\n\r\npublic class Dog extends RealmObject {\r\n  private String name;\r\n\r\n  @Backlink(parent = Owner.class, property = \"dogs\")\r\n  private RealmList<Owner> owners; // Returns list of all owners pointing to dog.\r\n\r\n  @Backlink(parent = Owner.class, property = \"dogs\")\r\n  private Owner owner; // This would throw an error if more than 1 owner existed or possible just return the first?\r\n}\r\n```\r\n\r\nThe Cocoa implementation allow custom filtering of the backlinks returned, but is that a use case we should support? I lean towards no.\r\n\r\nIt would also be nice to not have to specify which property to lookup (as it is not typed). Ideally the property in @Backlink is optional and automatically finds the right property if there is only one with that type. Otherwise it should be required.\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}