{"issue":{"created_at":"2011-11-24T20:53:07Z","state":"open","updated_at":"2011-11-25T04:57:13Z","user":{"gravatar_id":"df2f06fdc022e91ef9fcf9027fe439d0","id":205423,"url":"https://api.github.com/users/samsonasu","login":"samsonasu","avatar_url":"https://secure.gravatar.com/avatar/df2f06fdc022e91ef9fcf9027fe439d0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":3,"body":"If a has_many relationship is defined with a custom primary key, a new, unsaved record with that key set will not load the association.  This is because AR checks new_record? and assumes (correctly in normal situations) that an unsaved record couldn't possibly have any related records, so it skips the round trip to the database.  \r\n\r\nI believe this is an error, and the association should be loaded from the database.\r\n\r\n```ruby\r\nclass Author < ActiveRecord::Base \r\n  has_many :essays, :primary_key => :name, :as => :writer\r\nend\r\n\r\nAuthor.new(:name => \"David\").essays # => []\r\n                                    # => Should return [#<Essay ...>]\r\n```\r\n\r\nThis pull request fixes this issue.  I tested the 4 big connection adapters and added 2 tests.  \r\n\r\nI overrode the foreign_key_defined? method in has_many_association to handle this since that seemed to be written almost specifically for this purpose in has_many_through, but if that isn't the best way to handle this I'm open to discussion.  \r\n\r\nThanks","assignee":null,"id":2344864,"number":3748,"pull_request":{"patch_url":"https://github.com/rails/rails/pull/3748.patch","html_url":"https://github.com/rails/rails/pull/3748","diff_url":"https://github.com/rails/rails/pull/3748.diff"},"labels":[],"title":"New records should load has_many relationships with custom primary keys","closed_at":null,"html_url":"https://github.com/rails/rails/issues/3748","url":"https://api.github.com/repos/rails/rails/issues/3748","milestone":null},"action":"created","comment":{"created_at":"2011-11-25T04:57:13Z","updated_at":"2011-11-25T04:57:13Z","user":{"gravatar_id":"91160e88d86db6328f3e81313ae500c6","id":146214,"url":"https://api.github.com/users/vijaydev","login":"vijaydev","avatar_url":"https://secure.gravatar.com/avatar/91160e88d86db6328f3e81313ae500c6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"You should not commit the config.yml","id":2871353,"url":"https://api.github.com/repos/rails/rails/issues/comments/2871353"}}