Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Wrong join condition in SQL #102

Open
harmaty opened this Issue · 1 comment

2 participants

@harmaty

I have 3 models

class Login  < ActiveRecord::Base
  has_many :roles
end

class Property < ActiveRecord::Base
  has_many :roles
  has_one :owner, :through => :roles, :source => :login, :conditions => {:roles =>  {:relationship_type => 'owner'}}
end

class Role < ActiveRecord::Base
  belongs_to :login
  belongs_to :property
end
Property.search( :owner_email_eq => 'aharmaty@gmail.com')

Generates following SQL:

 SELECT `properties`.* FROM `properties` 
   LEFT OUTER JOIN `roles` ON `properties`.`id` = `roles`.`property_id` 
   LEFT OUTER JOIN `logins` ON `roles`.`relationship_type` = 'owner' 
   WHERE `logins`.`email` = 'aharmaty@gmail.com'

Condition: roles.relationship_type = 'owner' is wrong, it should be logins.id = roles.login_id

Problem appears only when condition for has_one :owner relation is defined, without condition search works fine

@plukacs

I have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.