Forum: Ruby on Rails How do i model this in Rails? (put down java equivalent design)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C5d343d2619b5c79e7e1ced6101ffff7?d=identicon&s=25 Ritvvij (Guest)
on 2009-06-07 04:30
(Received via mailing list)
Hello guys,

Need help!! Finding it hard to model the 'model' :P within the given
rails associations.

In java terms, my requirements are...

There are 3 entities - module, chapter and activity.

Chapter entity is a specilization of Module entity (inheritence)
Activity entity is a specialization of Module entity (inheritence)
And the tables would have looked like:
1. Module table = Module_Id, Entity_type, ....
2. Chapter = Chapter_id, .....
3. Activity = Activity_id, ......

Hence, if I create a chapter then the tables would be populated as:
Module table = Module_Id, Entity_type, .... = values ( 100,
chapter , .... )
Chapter table = chapter_id, ..... = values ( 100, .... )
Basically, the ids of chapter and module would be same and module
table would store the type.

Now, if I create a activity then the tables would be populated as:
Module table = Module_Id, Entity_type, .... = values ( 101,
activity , .... )
Activity table = activity_id, ..... = values ( 100, .... )
Basically, the ids of activity and module would be same and module
table would store the type.

Can you please guide me how I can model it similarly in rails 2.3.2?

Thanks in advance
Ritvvij Parrilkh
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-06-07 09:13
(Received via mailing list)
On Jun 7, 3:29 am, Ritvvij <Ritvi...@gmail.com> wrote:
> Activity entity is a specialization of Module entity (inheritence)
> table would store the type.
>
That wouldn't be the rails way of doing  it. In rails you'd probably
either use single table inheritance or a polymorphic association.

Fred
8a934bca2d929e50550e5d97e4e0ddcc?d=identicon&s=25 AGoofin (Guest)
on 2009-06-07 17:29
(Received via mailing list)
Does seem to be a bit of repetition in your description but it seems
straightforward.

You have a Module which has an Entity_type column

Each Module has many Chapters where Chapters has a column named
module_id.

Each Chapter has many Activities with similar foreign key constraints
or
You have one Activities table, in which case you don't specify a
relationship.

Once you set up the has_many and belongs_to pairs, Rails provides the
methods to interact with the data.

Checkout some ActiveRecord tutorials like this screencast -
http://www.railsenvy.com/2007/8/8/activerecord-tutorial
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2009-06-08 18:42
(Received via mailing list)
I'd also chime in that if you create a model named 'Module', Rails
will most likely break in really interesting ways, as Module is a
reserved word in Ruby...

--Matt Jones

On Jun 7, 3:12 am, Frederick Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.