Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2009, 09:53 PM   PM User | #1
Scrumpy.Gums
New Coder

 
Join Date: Aug 2007
Posts: 14
Thanks: 3
Thanked 1 Time in 1 Post
Scrumpy.Gums is an unknown quantity at this point
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.
__________________
"entia non sunt multiplicanda praeter necessitatem" - "Entities should not be multiplied beyond necessity" Occam's Razor
Scrumpy.Gums is offline   Reply With Quote
Old 06-09-2009, 01:16 AM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Scrumpy.Gums View Post
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
oesxyl is offline   Reply With Quote
Old 06-09-2009, 02:02 PM   PM User | #3
Scrumpy.Gums
New Coder

 
Join Date: Aug 2007
Posts: 14
Thanks: 3
Thanked 1 Time in 1 Post
Scrumpy.Gums is an unknown quantity at this point
One theme has many events. Events have only one theme, so one-to-many
__________________
"entia non sunt multiplicanda praeter necessitatem" - "Entities should not be multiplied beyond necessity" Occam's Razor
Scrumpy.Gums is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:58 PM.


Advertisement
Log in to turn off these ads.