Topic: HABTM-Association Insert_sql

trying to save a Project with HABTM-associated subprojects, I overwrite the default generated SQL, with calling the Name attribute of the mother project and each associated subproject. How do I specify correctly the associated subprojects Name? #{record.Name}, as in the example, leads to
       undefined local variable or method `record' for #<Project:0xb68396c>

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}" )} }

Any Suggestions?

Last edited by pherenjito (2012-08-31 10:04:55)