I'm developeing with Rails 2.3.8 Ruby 1.8.7 and PostgreSQL. I want to search records by relation.
UserGuildMaster
class UserGuildMaster < ActiveRecord::Base
has_one :leader, :foreign_key => 'guild_id', :class_name => 'UserGuildLog', :conditions => {:leader_flag => 1, :status => 1}
has_many :user_guild_logs, :foreign_key => 'guild_id', :class_name => 'UserGuildLog'
end
UserGuildLog
class UserGuildLog < ActiveRecord::Base
belongs_to :guild, :class_name => "UserGuildMaster"
belongs_to :user_master
belongs_to :user_character, :class_name => "UserCharacter"
end
UserCharacter
class UserCharacter < ActiveRecord::Base
end
I want to search UserGuildMaster which leader.user_character.logined_at is before 5days and which has less than 10 user_guild_logs.
My find conditions is below, but it raise error 'PGError: ERROR: schema "leader"'does not exist.
@user_guild_masters = UserGuildMaster.find(:all, :include => [{:leader => :user_character}, :user_guild_logs],
:conditions => ['leader.user_character.logined_at < ? AND user_guild_logs.size < ?', 5.days.ago, 10]
)
This Rails project is now on service and can't add or change column. I have no idea to finde these related records. Any ideas?