CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ruby & Ruby On Rails (http://www.codingforums.com/forumdisplay.php?f=44)
-   -   Model relationships (http://www.codingforums.com/showthread.php?t=168522)

Scrumpy.Gums 06-08-2009 09:53 PM

Model relationships
 
I have two DB tables: Themes and Events with the following relevant columns:
Code:

Theme:
integer month

Event:
datetime date_begin

So each theme has many events and they are linked through Event date_begin month and Theme month. My question is how to represent this in the models. I've tried the following and many variations in the Theme model but they don't work.
Code:

has_many :events, :through => :events_date_begin.month
I could store the month separately in the Event table but then it's redundant. Are there any better alternatives?

Thanks in advance.

oesxyl 06-09-2009 01:16 AM

Quote:

Originally Posted by Scrumpy.Gums (Post 826143)
I have two DB tables: Themes and Events with the following relevant columns:
Code:

Theme:
integer month

Event:
datetime date_begin

So each theme has many events and they are linked through Event date_begin month and Theme month. My question is how to represent this in the models. I've tried the following and many variations in the Theme model but they don't work.
Code:

has_many :events, :through => :events_date_begin.month
I could store the month separately in the Event table but then it's redundant. Are there any better alternatives?

Thanks in advance.

theme and events is a one-to-many or many-to-many relation?

best regards

Scrumpy.Gums 06-09-2009 02:02 PM

One theme has many events. Events have only one theme, so one-to-many :)


All times are GMT +1. The time now is 10:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.