Ritvvij
2009-Jun-07 02:29 UTC
How do i model this in Rails? (put down java equivalent design)
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
Frederick Cheung
2009-Jun-07 07:12 UTC
Re: How do i model this in Rails? (put down java equivalent design)
On Jun 7, 3:29 am, Ritvvij <Ritvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. >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> 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
AGoofin
2009-Jun-07 15:27 UTC
Re: How do i model this in Rails? (put down java equivalent design)
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 On Jun 6, 10:29 pm, Ritvvij <Ritvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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
Matt Jones
2009-Jun-08 16:42 UTC
Re: How do i model this in Rails? (put down java equivalent design)
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 7, 3:29 am, Ritvvij <Ritvi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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. > > 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 > > > 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