ajax-datatables-rails
ajax-datatables-rails copied to clipboard
Search using a polymorphic association
trafficstars
#models
class Message < ActiveRecord::Base
belongs_to :recipient, polymorphic: true
belongs_to :person, foreign_key: 'recipient_id', conditions: "message.recipient_type = 'person'"
end
class Person < ActiveRecord::Base
has_many :messages, as: :recipient
end
#datatable
def searchable_columns
@searchable_columns ||=['Person.name']
end
def get_raw_records
Message.includes(:person).where(id: options[:message_ids])
end
I get different errors based on what I try.
ERROR: missing FROM-clause entry for table "persons"
or
uninitialized constant Person
I've tried changing my get_raw_records to Message.includes(:recipient).where(id: options[:message_ids]) also
Any ideas on how to search with a polymorphic association
Join the tables dude.