Ransack: Searching polymorphic relation with namespaces

Created on 30 May 2018  路  1Comment  路  Source: activerecord-hackery/ransack

I try Searching polymorphic relation with namespaces.

Models

class Logistic::Order < ActiveRecord::Base
belongs_to :origin, polymorphic: true
belongs_to :destination, polymorphic: true
end

class Logistic::Location < ActiveRecord::Base
end

class Logistic::PickupPoint < ActiveRecord::Base
end

class Logistic::Warehouse < ActiveRecord::Base
end

I try:

Logistic::Order.ransack(origin_of_Location_type_name_cont: 'test')
and got the error:
NameError: uninitialized constant Kernel::Location from (irb):40
because he could not get the namespace of location

Also probe with:

Logistic::Order.ransack(origin_of_Logistic_Location_type_name_cont: 'test')

and got the error:

NameError: uninitialized constant Logistic::Order::Origin from (irb):41

Now I do not know what else to try

The 3 classes contain "name" attribute, my idea is to be able to make a query by making a join against Location, PickupPoint and Warehouse classes

My English isn't well, sorry

Most helpful comment

I try with:

Logistic::Order.ransack("destination_of_Logistic::Location_type_name_cont" => 'Maria Jose Paoli')
and works!
Thanks.

>All comments

I try with:

Logistic::Order.ransack("destination_of_Logistic::Location_type_name_cont" => 'Maria Jose Paoli')
and works!
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edgarbarrero picture edgarbarrero  路  4Comments

senid231 picture senid231  路  4Comments

MatsumotoHiroko picture MatsumotoHiroko  路  4Comments

timoschilling picture timoschilling  路  5Comments

seanfcarroll picture seanfcarroll  路  4Comments