You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a user model that has many projects.
Project has a relationship with tags that is a habtm.
Here are my simplified classes.
class User < ApplicationRecord
has_many :projects
end
class Project < ApplicationRecord
belongs_to :user
has_and_belongs_to_many :tags
end
class Tag < ApplicationRecord
has_and_belongs_to_many :projects
end
When i try to do a search on a project and do a not_in for tags_id I get the correct query output. Project.ransack(tags_id_not_in: [1,2]).result.to_sql
SELECT projects.*
FROM projects
WHERE projects.id NOT IN
(SELECT projects_tags.project_id
FROM projects_tags
INNER JOIN tags ON tags.id = projects_tags.tag_id
WHERE projects_tags.project_id = projects.id
AND NOT (tags.id NOT IN (1, 2)))
if i try to get the projects tags id where not in, through the User model, then i start getting the incorrect query.
SELECT users.*
FROM users
LEFT OUTER JOIN projects ON projects.user_id = users.id
WHERE users.id NOT IN
(SELECT projects_tags.project_id
FROM projects_tags
INNER JOIN tags ON tags.id = projects_tags.tag_id
WHERE projects_tags.project_id = users.id
AND NOT (tags.id NOT IN (1, 2)))
You can see the second query's subquery is selecting projects_tags.project_id and comparing it with users.id.
It is also doing this in the subquery WHERE projects_tags.project_id = users.id
I would think the query should be:
SELECT users.*
FROM users
LEFT OUTER JOIN projects ON projects.user_id = users.id
WHERE projects.id NOT IN
(SELECT projects_tags.project_id
FROM projects_tags
INNER JOIN tags ON tags.id = projects_tags.tag_id
WHERE projects_tags.project_id = projects.id
AND NOT (tags.id NOT IN (1, 2)))
I hope this was a detailed enough issue, If not, please let me know how i can give more information.
Ruby 2.5
Rails 5.2.4.1
Ransack 2.3.2
I have a user model that has many projects.
Project has a relationship with tags that is a habtm.
Here are my simplified classes.
When i try to do a search on a project and do a not_in for tags_id I get the correct query output.
Project.ransack(tags_id_not_in: [1,2]).result.to_sql
if i try to get the projects tags id where not in, through the User model, then i start getting the incorrect query.
User.ransack(projects_tags_id_not_in: [1,2]).result.to_sql
You can see the second query's subquery is selecting projects_tags.project_id and comparing it with users.id.
It is also doing this in the subquery
WHERE projects_tags.project_id = users.id
I would think the query should be:
I hope this was a detailed enough issue, If not, please let me know how i can give more information.
Here is the Gist
The text was updated successfully, but these errors were encountered: