-
Notifications
You must be signed in to change notification settings - Fork 133
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
Association chains that mention the same table twice produce incorrect results #8
Comments
Yeah, I see what you're doing, AR supports this, I just need to figure out how to tap into it. |
I also have something similar: class Direction < ActiveRecord::Base belongs_to :start_point, :class_name => "Point" belongs_to :end_point, :class_name => "Point" end class Point < ActiveRecord::Base has_one :direction end > Direction.start_point_name_eq("A").end_point_name_eq("B") Will give: |
I'm facing the same problem. |
I'm having a similar (or the same) problem, but with a single self-relationship in a table: Create a projectrails searchlogic_test Add to db/seeds.rbClient.create(:name => "Daniel (has no agency)") app/models/client.rbclass Client < ActiveRecord::Base Setup the databaserake db:migrate Add to config/environment.rbconfig.gem "searchlogic" Test on consolescript/console You'll see it runs the following SQLSELECT "clients".* FROM "clients" INNER JOIN "clients" agencies_clients ON "agencies_clients".id = "clients".agency_id WHERE (clients.name LIKE '%the%') But I think it should beSELECT "clients".* FROM "clients" INNER JOIN "clients" agencies_clients ON "agencies_clients".id = "clients".agency_id WHERE (agencies_clients.name LIKE '%the%') |
There were serious changes in Rails 3 that addresses this; Arel was introduced: "New Active Record chainable query language built on top of relational algebra". See http://guides.rails.info/3_0_release_notes.html |
Same issue here. |
Has anyone found a workaround for this? Seems I'm running into a related issue: Player.has_many :seasons, :as => :statable Player.search(:name_like => 'joe', :seasons_g_gte => 30, :teams_name_like => 'sun').all Throws this error: Player.search(:name_like => 'joe', :seasons_g_gte => 30).all |
Oh,I'm facing the same problem! And then ,who can provide the solution!! Thanks!!! |
For the example, take the following schema:
Product: id
ProductCategory: id, product_id, category_id
Category: id
Rows: You have one product in multiple categories
Product id: 1
ProductCategory id: 1, category_id: 1, product_id: 1
ProductCategory id: 2, category_id: 2, product_id: 1
Category id: 1
Category id: 2
Say you want to find all categories that contain a product which is also in category X.
The following scope returns 2 copies of category 1, since the where sql references the wrong product_categories table. It should return categories 1 and 2
Category.product_categories_product_product_categories_category_id_equals(1)
SELECT
categories
.* FROMcategories
INNER JOIN
product_categories
ON product_categories.category_id = categories.idINNER JOIN
products
ONproducts
.id =product_categories
.product_idINNER JOIN
product_categories
product_categories_products ON product_categories_products.product_id = products.idWHERE (product_categories.category_id = 235)
The text was updated successfully, but these errors were encountered: