On the screenshot above, category column is ‘product_type’, and product is ‘product_id’.
How can we do to create a link between this record and the product record. I’m looking into smart views/smart segments but I don’t find a way to do it.
Thanks for your answer !
Is there any work around ? I see that with smart relationship, I can create a belongs to association (which I succeed to make it work) but can I make it conditionnaly ?
Like
if object.product_type == wifi
belongs_to :wifi, reference: 'Wifi.id' do
object.product
end
end
Unfortunately there is no ideal workaround to have a single relationship that links to different types of record.
What you could do is to create as many Smart “belongs to” associations as the types of records your polymorphic association can handle, but it would create a lot of new columns in your table view and only one would be filled in per record.
Ok, you just have to fine tune you belongs_to declaration from my point of view.
belongs_to :wifi, reference: 'Wifi.id', search: search_wifi do
# if object.product is of type "Wifi"
# return object.product
# else
# return nil
end
belongs_to :mobile, reference: 'Mobile.id', search: search_mobile do
# if object.product is of type "Mobile"
# return object.product
# else
# return nil
end