Generate scaffold or model for join table?

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.

[email protected] ~/Desktop/strawr/app/models $
[email protected] ~/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
[email protected] ~/Desktop/strawr/app/models $
[email protected] ~/Desktop/strawr/app/models $ cat category.rb
class Category < ActiveRecord::Base
has_many : CategoryFeeds
end
[email protected] ~/Desktop/strawr/app/models $
[email protected] ~/Desktop/strawr/app/models $ cat feed.rb
class Feed < ActiveRecord::Base
has_many :CategoryFeeds
end
[email protected] ~/Desktop/strawr/app/models $
[email protected] ~/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
[email protected] ~/Desktop/strawr/app/models $
[email protected] ~/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
[email protected] ~/Desktop/strawr/app/models $

thanks,

Thufir

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

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

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

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,

Thufir

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs