{"action":"opened","issue":{"url":"https://api.github.com/repos/Shopify/identity_cache/issues/300","repository_url":"https://api.github.com/repos/Shopify/identity_cache","labels_url":"https://api.github.com/repos/Shopify/identity_cache/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/Shopify/identity_cache/issues/300/comments","events_url":"https://api.github.com/repos/Shopify/identity_cache/issues/300/events","html_url":"https://github.com/Shopify/identity_cache/issues/300","id":196049435,"number":300,"title":"IDC make models load order dependent.","user":{"login":"casperisfine","id":19192189,"avatar_url":"https://avatars.githubusercontent.com/u/19192189?v=3","gravatar_id":"","url":"https://api.github.com/users/casperisfine","html_url":"https://github.com/casperisfine","followers_url":"https://api.github.com/users/casperisfine/followers","following_url":"https://api.github.com/users/casperisfine/following{/other_user}","gists_url":"https://api.github.com/users/casperisfine/gists{/gist_id}","starred_url":"https://api.github.com/users/casperisfine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/casperisfine/subscriptions","organizations_url":"https://api.github.com/users/casperisfine/orgs","repos_url":"https://api.github.com/users/casperisfine/repos","events_url":"https://api.github.com/users/casperisfine/events{/privacy}","received_events_url":"https://api.github.com/users/casperisfine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-16T12:31:49Z","updated_at":"2016-12-16T12:31:49Z","closed_at":null,"body":"Currently IDC cause load order issue.\r\n\r\nImagine the following scenario:\r\n\r\n```ruby\r\n# app/models/post.rb\r\nclass Post < AR::Base\r\n  FOO = 42\r\n  has_many :comments\r\n  cache_has_many :comments\r\nend\r\n\r\n# app/models/comment.rb\r\nclass Comment < AR::Base\r\n  BAR = Post::FOO + 2\r\n  belongs_to :post\r\nend\r\n```\r\n\r\nIf you load `Comment` first, what will happen is that `Post` will be loaded while `Comment` is defined but the `belongs_to :post` relation isn't defined yet.\r\n\r\nThe problem is that `cache_has_many` and `cache_has_one` will invoke methods like [`ensure_cacheable_association`](https://github.com/Shopify/identity_cache/blob/8fdb3d34f0cc632ce2367afb3f08d6fd44ef9587/lib/identity_cache/configuration_dsl.rb#L298-L312) and [`add_parent_expiry_hook`](https://github.com/Shopify/identity_cache/blob/8fdb3d34f0cc632ce2367afb3f08d6fd44ef9587/lib/identity_cache/configuration_dsl.rb#L273-L283) that need the inverse association to be defined. As a result the load will raise an exception.\r\n\r\nAnother detrimental effect is that in a lazy loading environment (development), referencing a single model will likely lead to all models being loaded.\r\n\r\nI searched for ways to avoid this, but without any luck so far.\r\n\r\n@sgrif @rafaelfranca any ideas of API that would allow to lazily invoke those methods?\r\n\r\n"}}
{"actor":{"display_login":"casperisfine"}}