{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/6250","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/6250/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/6250/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/6250/events","html_url":"https://github.com/realm/realm-java/issues/6250","id":373582764,"node_id":"MDU6SXNzdWUzNzM1ODI3NjQ=","number":6250,"title":"How check is any references to Realm object?","user":{"login":"lmdic","id":303539,"node_id":"MDQ6VXNlcjMwMzUzOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/303539?v=4","gravatar_id":"","url":"https://api.github.com/users/lmdic","html_url":"https://github.com/lmdic","followers_url":"https://api.github.com/users/lmdic/followers","following_url":"https://api.github.com/users/lmdic/following{/other_user}","gists_url":"https://api.github.com/users/lmdic/gists{/gist_id}","starred_url":"https://api.github.com/users/lmdic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmdic/subscriptions","organizations_url":"https://api.github.com/users/lmdic/orgs","repos_url":"https://api.github.com/users/lmdic/repos","events_url":"https://api.github.com/users/lmdic/events{/privacy}","received_events_url":"https://api.github.com/users/lmdic/received_events","type":"User","site_admin":false},"labels":[{"id":662397242,"node_id":"MDU6TGFiZWw2NjIzOTcyNDI=","url":"https://api.github.com/repos/realm/realm-java/labels/O:User","name":"O:User","color":"006b75","default":false},{"id":3545600,"node_id":"MDU6TGFiZWwzNTQ1NjAw","url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-24T17:01:33Z","updated_at":"2018-10-25T11:41:48Z","closed_at":"2018-10-25T05:38:25Z","author_association":"NONE","body":"In my Android app I has realm object:\r\n\r\n```\r\npublic class Product extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private String name;\r\n    private float price;\r\n}\r\n\r\n```\r\n\r\nSometime I need to delete this object. But... I need delete it **ONLY** if no any references in Realm to this object.\r\nSo the question is: Can I check is any references to this object? Something like if c**ount of references = 0** then I can delete this object. Else I can't do it.\r\nIs it possible in Realm?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/433018425","html_url":"https://github.com/realm/realm-java/issues/6250#issuecomment-433018425","issue_url":"https://api.github.com/repos/realm/realm-java/issues/6250","id":433018425,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzAxODQyNQ==","user":{"login":"lmdic","id":303539,"node_id":"MDQ6VXNlcjMwMzUzOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/303539?v=4","gravatar_id":"","url":"https://api.github.com/users/lmdic","html_url":"https://github.com/lmdic","followers_url":"https://api.github.com/users/lmdic/followers","following_url":"https://api.github.com/users/lmdic/following{/other_user}","gists_url":"https://api.github.com/users/lmdic/gists{/gist_id}","starred_url":"https://api.github.com/users/lmdic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmdic/subscriptions","organizations_url":"https://api.github.com/users/lmdic/orgs","repos_url":"https://api.github.com/users/lmdic/repos","events_url":"https://api.github.com/users/lmdic/events{/privacy}","received_events_url":"https://api.github.com/users/lmdic/received_events","type":"User","site_admin":false},"created_at":"2018-10-25T11:41:48Z","updated_at":"2018-10-25T11:41:48Z","author_association":"NONE","body":"I has 3 Pojos that has ref. to pojo **Product** \r\n\r\nSmt like this:\r\n\r\n\r\n```\r\npublic class Profile extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private String name;\r\n    private Product product;\r\n}\r\n\r\npublic class User extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private String name;\r\n    private Image image;\r\n    private RealmList<Offer> offers;\r\n}\r\n\r\npublic class Image extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private String name;\r\n    private RealmList<Product> products;\r\n}\r\n\r\npublic class Offer extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private Product product;\r\n}\r\n```\r\n\r\nSo before delete **Product**  I need to understand to has any reference to object product. \r\nSo in my case: Is object Profile , Image,  Offer has references to Product.\r\nSo in Product I need smt like this:\r\n\r\n\r\n```\r\npublic class Product extends RealmObject {\r\n    @PrimaryKey\r\n    private long id;\r\n    private String name;\r\n    private float price;\r\n\r\n  @LinkingObjects(\"product\")\r\n  private final RealmResults<Profile> profiles;\r\n  @LinkingObjects(\"products\")\r\n  private final RealmResults<Image> images;\r\n  @LinkingObjects(\"product\")\r\n  private final RealmResults<Offer> offers;\r\n}\r\n```\r\n\r\nSo now I can create query to Realm that:\r\n Give me list of all **profiles** that contain this **product**\r\nor\r\nGive me list of all **images** that contain this **product**\r\nor\r\nGive me list of all **offers** that contain this **product**\r\n\r\nIs I'm right?\r\n"}}
{"actor":{"display_login":"lmdic"}}