This article was migrated from http://rai
yuguiさんのhas_one :throughはABD的にRailsを使うのには欠かせない存在です。 今回は、オリジナルのhas_one :throughを拡張して、Unsaved objectも扱えるようにしてみました。
class ActiveReco上記のコードをオリジナルのコードに追加すると、Unsaved objectに対しても、アソシエーションを参照することができるようになります。rd::Associ ations::Ha sOneThroug hAssociati on < ActiveRecord::Associations::HasOneAssociation private 〜 略 〜 def load_target if !loaded? && @owner.new_record? table_name = @reflection.through_reflection.table_name @target = @owner.send(table_name.singularize).send(@reflection.name) end super end end
member = Member.new member.build_membership(:group => Group.new) member.groupというわけで、yuguiさんお願いしますー。
This article was migrated from http://rails.office.drecom.jp/takiuchi/archive/99
posted by
genki
on Mon 11 Sep 2006
at 23:31