-
Notifications
You must be signed in to change notification settings - Fork 51
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
[Error] When using joining
with on
, DSL refers the association to wrong table name or undefined table alias
#65
Comments
Hmm this is interesting. Could you create a reproducible test case based on this example: https://github.com/rzane/baby_squeel/blob/master/ISSUE_TEMPLATE.md |
require 'bundler/inline'
require 'minitest/spec'
require 'minitest/autorun'
gemfile true do
source 'https://rubygems.org'
gem 'activerecord', '~> 4.2.7.1' # which Active Record version?
gem 'sqlite3'
gem 'baby_squeel', github: 'rzane/baby_squeel'
end
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :courses, force: true do |t|
end
create_table :enrollments, force: true do |t|
t.references :course, index: true, foreign_key: true
t.float :progress, default: 0, null: false
end
end
class Course < ActiveRecord::Base
has_many :enrollments
end
class Enrollment < ActiveRecord::Base
belongs_to :course
end
class BabySqueelTest < Minitest::Spec
it 'works' do
scope = Course.joining{ enrollments.on(id == enrollments.course_id) }.where.has{ enrollments.progress == 100 }
scope.to_sql.must_equal <<-SQL.squish
SELECT "courses".*
FROM "courses"
INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id"
WHERE "enrollments"."progress" = 100.0
SQL
end
end Test result
|
The problem also exists on Rails 5 |
+1 rails 4.1.0 |
+1 |
using @Looooong's syntax in the meantime:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue
will produce the following query:
Notice the
WHERE
condition, it'senrollments_courses
instead ofenrollments
, or the table aliasenrollments_courses
is not defined.On the other hand, this code generates query correctly:
The expected query is:
I'm using Rails version 4.2.7.1, Ruby version 2.3.3, Baby Squeel version 1.1.4.
The text was updated successfully, but these errors were encountered: