Rails query with delegate fields of a model

rails-activerecord, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.1, ruby-on-rails-3.2

Solution

Problem can solved by using `joins` and `where`. But not sure if this is what you are looking for.

reservations = Reservation.joins(:content).where("contents.title = ?","some_title")

Problem

Hi am having two models with has_one association. I need to search with delegate fields. ``` **Model 1:** class Reservation < ActiveRecord::Base belongs_to :content delegate :type, :title, :to => :content end **Model 2:** class Content < ActiveRecord::Base has_one :reservation end ``` The following query works fine, because of delegate: ``` reservations = Reservation.last reservations.title ~ Content Load (0.6ms) SELECT `contents`.* FROM `contents` WHERE `contents`.`id` = 95 LIMIT 1 => "Birthday Party" ``` Now i need to do query using delegate fields: ``` reservations = Reservation.where("title = ?","some_title") ``` it returns error: ``` Unknown column 'title' in 'where clause' ``` How can i solve the problem? is that am doing in correct way? Thanks for reading my question.

Original source