I''m using
<http://wiki.rubyonrails.org/rails/pages/ThroughAssociations>
as a guide, but it doesn''t say how to generate the model for the join
table. Which of the following would be preferable:
script/generate scaffold category_feeds
or
script/generate model category_feeds
So long as it''s kosher, I prefer the scaffold generator. For now the
join table only has foreign keys for fields, but that may change down the
road.
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ ll
total 8
-rw-r--r-- 1 thufir users 66 Dec 12 02:40 category.rb
-rw-r--r-- 1 thufir users 61 Dec 12 02:41 feed.rb
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ cat category.rb
class Category < ActiveRecord::Base
has_many : CategoryFeeds
end
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ cat feed.rb
class Feed < ActiveRecord::Base
has_many :CategoryFeeds
end
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ ll /home/thufir/Desktop/
strawr/db/migrate/
total 12
-rw-r--r-- 1 thufir users 199 Dec 12 02:32 001_categories.rb
-rw-r--r-- 1 thufir users 184 Dec 12 02:32 002_feeds.rb
-rw-r--r-- 1 thufir users 251 Dec 12 02:32 003_category_feeds.rb
thufir@arrakis ~/Desktop/strawr/app/models $
thufir@arrakis ~/Desktop/strawr/app/models $ cat /home/thufir/Desktop/
strawr/db/migrate/003_category_feeds.rb
class CategoryFeeds < ActiveRecord::Migration
def self.up
create_table :category_feeds do |table|
table.column :category_id, :integer
table.column :feed_id, :integer
end
end
def self.down
drop_table :category_feeds
end
end
thufir@arrakis ~/Desktop/strawr/app/models $
thanks,
Thufir
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thufir wrote:> I''m using <http://wiki.rubyonrails.org/rails/pages/ThroughAssociations> > as a guide, but it doesn''t say how to generate the model for the join > table. Which of the following would be preferable: > > script/generate scaffold category_feeds > > or > > script/generate model category_feeds >you just need a model, unless you are going to have more then just the link fields in the many table. this explains with samples: http://gemblon.com/railshowto/?p=19 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 12, 12:27 pm, "gemblon (t.b.)" <rails-mailing-l...@andreas- s.net> wrote: [...]> you just need a model, unless you are going to have more then just the > link fields in the many table. > > this explains with samples: > > http://gemblon.com/railshowto/?p=19 > -- > Posted viahttp://www.ruby-forum.com/.I might add fields to the category_feeds table, but for now it strictly manages the many-to-many relationship between the categories and feeds tables. If I run "script/generate model category_feeds" it will generate the corresponding model? This won''t paint me into a corner if I want to add fields to this table down the road (so long as I manage the "rake db:migrate" commands)? There''s nothing to be gained by "script/generate scaffold category_feeds"? thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thufir wrote:> On Dec 12, 12:27 pm, "gemblon (t.b.)" <rails-mailing-l...@andreas- > s.net> wrote: > [...] >> you just need a model, unless you are going to have more then just the >> link fields in the many table. >> >> this explains with samples: >> >> http://gemblon.com/railshowto/?p=19 >> -- >> Posted viahttp://www.ruby-forum.com/. > > > I might add fields to the category_feeds table, but for now it > strictly manages the many-to-many relationship between the categories > and feeds tables. If I run "script/generate model category_feeds" it > will generate the corresponding model? This won''t paint me into a > corner if I want to add fields to this table down the road (so long as > I manage the "rake db:migrate" commands)? > > There''s nothing to be gained by "script/generate scaffold > category_feeds"? > > thanks, > > Thufirwell, i think i explained that bad in my posting. just do the :through method explained in the link, using a model. then you are prepared in the future. if you scaffold to get the model, that is fine (in my opinion), you are just set up for future stuff. you may not using the scaffolded view or controller for now, but they are there if you need them in the future. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 13 Dec 2007 06:16:55 +0100, gemblon (t.b.) wrote:> well, i think i explained that bad in my posting. just do the :through > method explained in the link, using a model. then you are prepared in > the future. if you scaffold to get the model, that is fine (in my > opinion), you are just set up for future stuff. you may not using the > scaffolded view or controller for now, but they are there if you need > them in the future.Thanks. It''s one small step at a time for me on this. I''ll go with generating a scaffold as it does more and doesn''t cause harm. -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---