Skip to content

Instantly share code, notes, and snippets.

@graywh
Created February 13, 2012 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graywh/1818459 to your computer and use it in GitHub Desktop.
Save graywh/1818459 to your computer and use it in GitHub Desktop.
ActiveRecord 3.0.9 error -- has_one :through a has_one with :conditions
class Asset < ActiveRecord::Base
has_many :ownerships
has_many :owners, :through => :ownerships
has_one :current_ownership, :class_name => Ownership.name, :conditions => { :current => true }
has_one :current_owner, :through => :current_ownership, :source => :owner
end
Asset.joins(:current_owner).all
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'owners.current' in 'on clause': SELECT `assets`.* FROM `assets` INNER JOIN `ownerships` ON `assets`.`id` = `ownerships`.`asset_id` INNER JOIN `owners` ON `owners`.`current` = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment