Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scopes not referencing aliased table names #57

Open
mengqing opened this issue Jun 14, 2017 · 0 comments
Open

scopes not referencing aliased table names #57

mengqing opened this issue Jun 14, 2017 · 0 comments

Comments

@mengqing
Copy link

say if I have the following associations

class User < ApplicationRecord
  has_many :active_projects, -> { with_state(:active) }, class_name: Project
end

class Project < ApplicationRecord
  belongs_to :user

  state_machine :state, initial: :pending do
    state :active
  end
end

And if I do the following query

> Project.joins(user: :active_projects).to_sql
=> "SELECT `projects`.* FROM `projects` INNER JOIN `users` ON `users`.`id` = `projects`.`user_id` INNER JOIN `projects` `active_projects_users` ON `active_projects_users`.`user_id` = `users`.`id` AND (`projects`.`state` IN ('active'))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant