-i searched through the news group but couldn't find the answer for my problem. example:
----------- classes ---------- class Car < ActiveRecord::Base has_one :colour def after_create() colour = Colour.new colour.name = 'colour1' colour.save end end
class Chair < ActiveRecord::Base has_one :colour end
class Colour < ActiveRecord::Base end -------------- tables --------- create table cars(id int PRIMARY KEY NOT NULL AUTO_INCREMENT,name varchar(50),colour_id int NOT NULL, primary key(id));
create table chairs(id int PRIMARY KEY NOT NULL AUTO_INCREMENT,name varchar(50),colour_id int NOT NULL);
create table colours(id int PRIMARY KEY NOT NULL AUTO_INCREMENT,name varchar(50));
- i consider it a many to one relation because diferent types of items are refering to one type (Car and Chair both have colour). - i wrote the models as above i create a Car object, i save it but alwayes my colour_id in the database remains 0. I would appreciate if your could give me a hint.