Hi all,
Im slowly moving forward, but there''s something a miss. I can save some
relational records to tables, but only once. For an unknown reason, the
primary key (id) of the child table is not automatically increased. (I can
only perform one save, (the first records id field holds the value
''0'') and
during the next save it says:
Mysql::Error: Duplicate entry ''0'' for key 1: INSERT INTO
project_contacts ...
The field that holds the foreign key (project_id) is set correct btw.
What''s
eventually needed is to copy contact info from another contact table all
together.
Some info:
## Models:
class Project < ActiveRecord::Base
has_one :project_contact
end
class ProjectContact < ActiveRecord::Base
belongs_to :project
end
## Controller Methods
def new_project
@project = Project.new
@contacts_list = Contact.find_by_sql(''select t1.name, t2.firstname,
t2.lastname, t2.id from companies AS t1, contacts AS t2 where t1.id =
t2.company_id order by t1.name'')
## Showing a nice dropdown list with "Company - Fname Lname"
## Thanx to Chris Hall
@contacts_list = @contacts_list.collect { |c| [ c.name + " - " +
c.firstname
+ " " + c.lastname ] }
render_action ''edit_project''
end
def create_project
@project = Project.new(@params[''project''])
@project_contact = ProjectContact.new(@params[''id''])
@project.project_contact = @project_contact
#@project.project_contact.save
if @project.save
flash[:notice] = ''Project was successfully created.''
redirect_to :action => ''show_project'', :id =>
@project.id
else
render :action => ''edit_project''
end
end
Gerard -hope-my-mails-dont-feel-like-spam-yet- Petersen
--
"Who cares if it doesn''t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."
My $Grtz =~ Gerard;
~
:wq!