-
-
Notifications
You must be signed in to change notification settings - Fork 829
Open
Description
Relation is "Parent -> Child -> Grandchild". In this case, the association breaks down
Models
class Parent
...
has_many :childs
end
class Child
...
belongs_to :parent
has_many :grandchilds
end
class Grandchild
...
belongs_to :child
end
Seach sample
Parent.ransack({childs_grandchilds_name_not_in: 'test'}).result.to_sql
Get SQL
SELECT `parents`.*
FROM `parents`
LEFT OUTER JOIN `childs` ON `childs`.`parent_id` = `parents`.`id`
WHERE `parents`.`id` NOT IN (
SELECT `grandchilds`.`child_id`
FROM `grandchilds`
WHERE `grandchilds`.`child_id` = `parents`.`id`
AND NOT (`grandchilds`.`name` NOT IN 'test')
)
I assume this is the outcome
SELECT `parents`.*
FROM `parents`
LEFT OUTER JOIN `childs` ON `childs`.`parent_id` = `parents`.`id`
WHERE `childs`.`id` IN (
SELECT `grandchilds`.`child_id`
FROM `grandchilds`
WHERE (`grandchilds`.`name` NOT IN 'test')
)
I think there is something wrong with the comparison of Parent.id and Child.id
Ruby: ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
Rails: 6.1.6
Ransack: 3.2.1
DB: mysql Ver 14.14 Distrib 5.7.41, for Linux (x86_64) using EditLine wrapper
clgiovannelli and zn-nsasaki
Metadata
Metadata
Assignees
Labels
No labels