{"action":"closed","issue":{"url":"https://api.github.com/repos/rails/rails/issues/20995","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/20995/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/20995/comments","events_url":"https://api.github.com/repos/rails/rails/issues/20995/events","html_url":"https://github.com/rails/rails/issues/20995","id":96778360,"number":20995,"title":"Save many-to-many objects based on association primary key","user":{"login":"himesh-r","id":2097579,"avatar_url":"https://avatars.githubusercontent.com/u/2097579?v=3","gravatar_id":"","url":"https://api.github.com/users/himesh-r","html_url":"https://github.com/himesh-r","followers_url":"https://api.github.com/users/himesh-r/followers","following_url":"https://api.github.com/users/himesh-r/following{/other_user}","gists_url":"https://api.github.com/users/himesh-r/gists{/gist_id}","starred_url":"https://api.github.com/users/himesh-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/himesh-r/subscriptions","organizations_url":"https://api.github.com/users/himesh-r/orgs","repos_url":"https://api.github.com/users/himesh-r/repos","events_url":"https://api.github.com/users/himesh-r/events{/privacy}","received_events_url":"https://api.github.com/users/himesh-r/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/stale","name":"stale","color":"444444"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-23T10:13:51Z","updated_at":"2016-02-03T04:40:48Z","closed_at":"2016-02-03T04:40:48Z","body":"I have a scenario where I am using a primary key different than id.\r\n```ruby\r\n  class Client < ActiveRecord::Base\r\n    has_many :clients_health_conditions, primary_key: :ext_id\r\n    has_many :health_conditions, through: :clients_health_conditions, primary_key: :ext_id\r\n  end\r\n```\r\n\r\nSo when I try to associate the two models in this way:\r\n\r\n```ruby\r\n  @client.health_condition_ids = ['4']\r\n```\r\n\r\nIt gives me an error because, as per rails 'ids_writer' method, it checks for an object with id = 4, not considering my association primary_key. I guess it should be considering association primary_key."}}