Searching on the Polymorph Model #161

Closed
rweng opened this Issue Nov 10, 2012 · 2 comments

Comments

Projects
None yet
3 participants

rweng commented Nov 10, 2012

class Property < ActiveRecord::Base
  belongs_to :property, polymorphic: true
end

class Properties::Apartment < ActiveRecord::Base
  has_one :property, as: :property, dependent: :destroy
  attr_accessible :has_balcony
end

Now I want to search on Property for an apartment with balcony. My current take:

Property.where(property_type: Properties::Apartment).search(property_has_balcony_true: '1')

unfortunately, it gives me only the sql:

"SELECT \"properties\".* FROM \"properties\"  WHERE \"properties\".\"property_type\" = 'Properties::Apartment'"

I have a similar case where Property has_one Rentable and has_one Buyable, there it works by just specifying the association. But there, the polymorphic lies within Rentable and Buyable. Can you tell if whether searching on the Polymorph is possible and what I did wrong? I would like avoiding to search directly on Properties::Apartment.

Thanks,

Robin

llopez commented Sep 29, 2014

I have the same issue. Can anyone help? Does this gem have support yet?

Member

jonatack commented Sep 29, 2014

Issues are for bugs reports as per the Contributing Guidelines, and this "how to?" question is 2 years old without updates, so it is certainly stalled.

Does this gem have support yet?

@llopez Ransack is free, open source DIY software, not commercial software with customer support. You might try StackOverflow.

@jonatack jonatack closed this Sep 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment