{"action":"created","issue":{"url":"https://api.github.com/repos/orgsync/active_interaction/issues/376","repository_url":"https://api.github.com/repos/orgsync/active_interaction","labels_url":"https://api.github.com/repos/orgsync/active_interaction/issues/376/labels{/name}","comments_url":"https://api.github.com/repos/orgsync/active_interaction/issues/376/comments","events_url":"https://api.github.com/repos/orgsync/active_interaction/issues/376/events","html_url":"https://github.com/orgsync/active_interaction/issues/376","id":171329629,"number":376,"title":"Dependant keys","user":{"login":"antulik","id":831942,"avatar_url":"https://avatars.githubusercontent.com/u/831942?v=3","gravatar_id":"","url":"https://api.github.com/users/antulik","html_url":"https://github.com/antulik","followers_url":"https://api.github.com/users/antulik/followers","following_url":"https://api.github.com/users/antulik/following{/other_user}","gists_url":"https://api.github.com/users/antulik/gists{/gist_id}","starred_url":"https://api.github.com/users/antulik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antulik/subscriptions","organizations_url":"https://api.github.com/users/antulik/orgs","repos_url":"https://api.github.com/users/antulik/repos","events_url":"https://api.github.com/users/antulik/events{/privacy}","received_events_url":"https://api.github.com/users/antulik/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/orgsync/active_interaction/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/orgsync/active_interaction/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-08-16T05:46:20Z","updated_at":"2016-09-13T23:16:46Z","closed_at":"2016-09-13T23:16:46Z","body":"This is an idea/request for the feature. Would be nice to have ability to define dependant keys. Let's assume example\r\n\r\n```ruby\r\nclass Update < ActiveInteraction::Base\r\n  integer :user_id\r\n  object :user, default: -> { User.find(user_id) }\r\n\r\n  def execute\r\n  end\r\nend\r\n```\r\n\r\nI've found it's very convenient to define both `user_id` and `user`. In code you would use `user_id` as it is required for using class as a background job. \r\n\r\nIn tests you can pass `user` object directly and don't need to mock anything. Which makes it extremely easy to test.\r\n\r\nSo you should pass either `user_id` or `user`. But not both and exactly one of them. Right now `active_interaction` does not allow that. \r\n\r\nAs a proposed solution\r\n\r\n```ruby\r\nclass Update < ActiveInteraction::Base\r\n  integer :user_id\r\n  object :user, default: -> { User.find(user_id) }, depends_on: :user_id\r\n\r\n  # or\r\n\r\n  integer :user_id, provides: :user\r\n  object :user, default: -> { User.find(user_id) }\r\n\r\n\r\n  def execute\r\n  end\r\nend\r\n```\r\n\r\nin the example `user_id` will be marked as virtual and only `user` will be available in the code.\r\n\r\nThis is just an idea and I'd like to see what others think as it worked very well for me so far.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/orgsync/active_interaction/issues/comments/246856253","html_url":"https://github.com/orgsync/active_interaction/issues/376#issuecomment-246856253","issue_url":"https://api.github.com/repos/orgsync/active_interaction/issues/376","id":246856253,"user":{"login":"tfausak","id":408753,"avatar_url":"https://avatars.githubusercontent.com/u/408753?v=3","gravatar_id":"","url":"https://api.github.com/users/tfausak","html_url":"https://github.com/tfausak","followers_url":"https://api.github.com/users/tfausak/followers","following_url":"https://api.github.com/users/tfausak/following{/other_user}","gists_url":"https://api.github.com/users/tfausak/gists{/gist_id}","starred_url":"https://api.github.com/users/tfausak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tfausak/subscriptions","organizations_url":"https://api.github.com/users/tfausak/orgs","repos_url":"https://api.github.com/users/tfausak/repos","events_url":"https://api.github.com/users/tfausak/events{/privacy}","received_events_url":"https://api.github.com/users/tfausak/received_events","type":"User","site_admin":false},"created_at":"2016-09-13T23:16:46Z","updated_at":"2016-09-13T23:16:46Z","body":"I'm going to close this. ActiveInteraction is flexible enough to let you do what you want here. I don't want to add this complexity to ActiveInteraction's API. Not only is it difficult to understand, it's difficult to introspect. "}}
{"actor":{"display_login":"tfausak"}}