Почему ассоциация client_destination возвращает ноль, если она не была "включена" из исходного поиска модели!?
class Placement < ActiveRecord::Base
belongs_to :client_destination_type
belongs_to :client_destination,
:polymorphic => true,
:foreign_type => 'client_destination_type_class_name'
def client_destination_type_class_name
client_destination_type.class_name
end
end
Без включения (не работает):
ruby-1.9.2-p0 :021 > Placement.last.client_destination
Placement Load (0.5ms) SELECT `placements`.* FROM `placements` WHERE (placements.deleted_at IS NULL) ORDER BY `placements`.`id` DESC LIMIT 1
=> nil
С включением (работами):
ruby-1.9.2-p0 :022 > Placement.last(:include => :client_destination).client_destination
Placement Load (0.7ms) SELECT `placements`.* FROM `placements` WHERE (placements.deleted_at IS NULL) ORDER BY `placements`.`id` DESC LIMIT 1
ClientDestinationType Load (0.4ms) SELECT `client_destination_types`.* FROM `client_destination_types` WHERE `client_destination_types`.`id` = 2 LIMIT 1
ClientSite Load (0.4ms) SELECT `client_sites`.* FROM `client_sites` WHERE `client_sites`.`id` IN (3000018)
=> #<ClientSite id: 3000018, name: "WTF.com", created_at: "2011-08-09 12:23:51", updated_at: "2011-08-09 12:23:51", user_group_id: 23510, client_ad_tag_code_id: nil>