SpeedJet
June 10th, 2005, 08:47 PM
Hello Forum!
I'm starting with Ruby and RoR from zero, read almost every news, doc and tutorial for the past 2 weeks and installed just monday to start modeling my webapp.
The thing is this: my background on DB and SQL sucks... really. Just created a few php-hand-coded webapps but nothing so rational and so objective as Ruby (and Rails) force me (in the good way, of course).
Start designing in php a webapp for managing TV ads breaks (these ones you see in the middle of a tv show).
What I want to achieve is create it 100% on Rails.
based on the objective/rational model, I have a few/bunch of channels, each one have N breaks with M number of ads on them.
So if I do:
ch = Channel.find(1)
# check if have some breaks on it:
if ch.breaks.length > 0
# list each ads on each break:
for break in ch.breaks
puts "break starttime:" + break.starttime
for ad in break.ads
puts "ad id:" + ad.id +", on break id:" + break.id + ", position:" + ad.position
end
end
Because ads are reusable, the position of each ad on the "playlist" may vary, so cannot store it on the ads table of my DB, right?
so:
Channel model:
has_many :breaks
Break model:
belongs_to :channel
has_many :ads
Ad model:
has_and_belongs_to_many :breaks, :order => "position DESC"
I'm in the good path, right?
Now, the worst part is translate this to a SQL, so the tables are easy to setup, and the join_table of breaks and ads will looks like:
breaks_ads
break_id
ad_id
position (INT)
the two _id fields are ForeignKeys (FK)...
Now... how to create a decent SQL from this? I really don't understand FK stuff... complex queries (aka: unoptimized mosters) I have done for PHP.. but now this is new for me :confused:
Any help?
I'll really apreciate any comment on this.
Please excuse my poor english.
Luis
I'm starting with Ruby and RoR from zero, read almost every news, doc and tutorial for the past 2 weeks and installed just monday to start modeling my webapp.
The thing is this: my background on DB and SQL sucks... really. Just created a few php-hand-coded webapps but nothing so rational and so objective as Ruby (and Rails) force me (in the good way, of course).
Start designing in php a webapp for managing TV ads breaks (these ones you see in the middle of a tv show).
What I want to achieve is create it 100% on Rails.
based on the objective/rational model, I have a few/bunch of channels, each one have N breaks with M number of ads on them.
So if I do:
ch = Channel.find(1)
# check if have some breaks on it:
if ch.breaks.length > 0
# list each ads on each break:
for break in ch.breaks
puts "break starttime:" + break.starttime
for ad in break.ads
puts "ad id:" + ad.id +", on break id:" + break.id + ", position:" + ad.position
end
end
Because ads are reusable, the position of each ad on the "playlist" may vary, so cannot store it on the ads table of my DB, right?
so:
Channel model:
has_many :breaks
Break model:
belongs_to :channel
has_many :ads
Ad model:
has_and_belongs_to_many :breaks, :order => "position DESC"
I'm in the good path, right?
Now, the worst part is translate this to a SQL, so the tables are easy to setup, and the join_table of breaks and ads will looks like:
breaks_ads
break_id
ad_id
position (INT)
the two _id fields are ForeignKeys (FK)...
Now... how to create a decent SQL from this? I really don't understand FK stuff... complex queries (aka: unoptimized mosters) I have done for PHP.. but now this is new for me :confused:
Any help?
I'll really apreciate any comment on this.
Please excuse my poor english.
Luis