导轨 3.2.3,红宝石 1.9.3p194
尝试使用与 HABTM 关联的子项目保存项目时,我覆盖了默认生成的 SQL,并调用了母项目和每个关联子项目的 Name 属性。如何正确指定关联的子项目名称?#{record.Name},如示例中所示,导致 NameError: undefined local variable or method `record' for #
has_and_belongs_to_many :subproject, :class_name => "Project",
:join_table => "project_subproject", :foreign_key => "projectname", :association_foreign_key => "subprojectname",
:finder_sql => proc { %{SELECT `project`.* FROM `project` INNER JOIN `project_subproject` ON `project`.`name` = `project_subproject`.`subprojectname` WHERE `project_subproject`.`projectname` = '#{self.Name}' } },
#TODO: find correct expression for insert sql
:insert_sql => proc { %{INSERT INTO `project_subproject` (`projectname`, `subprojectname`) VALUES ( "#{self.Name}","#{record.Name}" )} }
有什么建议么?