Closed mcm-ham closed 8 years ago
Was this possible without explicitly joining?
Sorry I don't think it was. I think I just got confused with cancancan syntax which allows:
can :index, Tag, note: {name: 'title'}
But after adding postgres_ext-serializers it then generates invalid sql like above.
A workaround people can use is:
class Tag < ActiveRecord::Base
scope :name_is_title, -> { joins(:note).where(notes: {name:'title'}) }
end
can :index, Tag, Tag.name_is_title do |tag|
tag.note.title == 'title'
end
Need to check if this is still an issue. A (skipped) test was added in db578390 (nested filtering support in sideloading_test.rb).
As far as I can seem this works fine on master, but you have to use where(notes: { name: 'Title' })
(not :note
) or it won't work. That's because activerecord does not expand symbols in the were to the table name of the joined relation. It has nothing to do with postgres_ext-serializers.
If this was previously broken, then either #44 or #45 has fixed it.
Btw. if you don't want to manually specify the correct table name in the where
, you can use merge
:
Tag.joins(:note).merge(Note.where(name: 'Title'))
If I serialize this:
It produces SQL like this:
Instead of doing a table join on offers.