Managing a 1:1 relationship

Bit of a noddy question this, but I am getting confused and would welcome some help.

I have two classes, called Site and Theme. In my model, a Site has_one theme and a Theme belongs_to a site (and I set them up like that in my model files). In my migration files I put a column in the sites table for theme_id. Having created the controllers everything is starting to look OK on the scaffolding web pages. However, I wanted to check out the relationships in the console prior to adding code to pull the different models together, and thought that this would work:

sitetest = Site.find 1

[result OK]

[result OK]


1 [that's OK]

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'themes.site_id' in 'where clause': SELECT * FROM themes WHERE (themes.site_id = 1) LIMIT 1

I thought that since a Site has a Theme, this should have worked. I'm now a little confused about whether my models are correct. I did wonder whether in fact I should have put a site_id column in my themes table instead of a theme_id column in my sites table, but it seems counter-intuitive.

If someone could help me to clear the fog, I'd be very grateful.



Oops - except it's not a 1:1 relationship after all. I screwed up. A
Site has one Theme, but a Theme can be used in a whole range of
Sites, so it is actually 1:many isn't it?

Sorry to waste your time. :frowning: