Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

has_many :through assoc_ids incorrect with :primary_key option on belongs_to source

#6376

Initially reported in the comments at #2421 Problem with has_many :through and alternate keys


Okay, a bit more information. I have:

class Phenotype
  has_many :observations
  has_many :genes, :through => :observations
end

class Observation
  belongs_to :gene, :primary_key => :entrez_id
end

It used to be that when I did Phenotype.find(48291).gene_ids, it would give me the entrez_id attribute rather than the primary keys. This makes sense. I don't use id for anything at all, which is why I set entrez_id as the primary. Unfortunately, in the current beta, gene_ids returns the :id attribute on each gene.

There are obvious workarounds, but this is obnoxious, and it can't be the correct behavior.


Reported by Jon Leighton · February 5th, 2011 @ 08:39 AM

State: resolved
Milestone: 3.x
Assigned to: Jon Leighton Jon Leighton
Importance: Low

Activity

  1. Jon Leighton
  2. Repository
    Repository
    • State changed from open to resolved

    (from [f0b98050296b57d95dbc789f8e52fa82499d151a]) Ensure that association_ids uses the correct attribute where the association is a has_many :through with a :primary_key option on the source reflection. [#6376 has_many :through assoc_ids incorrect with :primary_key option on belongs_to ... state:resolved] https://github.com/rails/rails/commit/f0b98050296b57d95dbc789f8e52f...

    February 18th, 2011 @ 05:15 PM