Allow overloading of attributes
Reported by Brian Durand | June 18th, 2010 @ 06:37 PM
I'd like it if sunspot supported overloading of attributes in the schema so that a setup would work even on models that don't implement every attribute. This would make it easier to use sunspot with some setups that use single table inheritance, etc.
The fix would be to just check the attribute before invoking it on line 17 of lib/sunspot/data_extractor.rb
class AttributeExtractor
def initialize(attribute_name)
@attribute_name = attribute_name
end
def value_for(object)
object.send(@attribute_name)
end
end
becomes
class AttributeExtractor
def initialize(attribute_name)
@attribute_name = attribute_name
end
def value_for(object)
object.send(@attribute_name) if object.respond_to?(@attribute_name)
end
end
Comments and changes to this ticket
-

mat June 18th, 2010 @ 06:43 PM
- State changed from new to rejected
You can call
searchable/Sunspot.setupin your subclasses to declare the fields that only exist in those subclasses -- Sunspot fully supports inheritance.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Awesome Solr interaction for Ruby