Hello friendly railers! I''m really having trouble getting my head around database relationships. Is it set up in the model, or in the migration? I''m building a basic cart for tshirts, and this is what i''ve had in mind: two tables, designs and sizes. designs sizes name name thumb image then i''ll need another availability table so we can keep track of what''s in stock, and i''m thinking the view will look like so: design size in stock ------------------------------- Star S 25 [text inputs] M 8 L 19 Shuttle S 5 M 0 L 15 I''m sure this is fairly straight forward, but it seems every tute on relationships in rails 2 uses different methods. As far as i can understand, you really have to get things set up spot-on first time around, it''s a bit overwhelming. Any help would be great, thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
Sounds like you want something like has_many :through. class Design < ActiveRecord::Base has_many :sizes, :through => :availability end class Size < ActiveRecord::Base has_many :designs, :through => :availability end class Availability < ActiveRecord::Base #You might have to set the table name here. belongs_to :design belongs_to :size end In the availability table you''ll have a design_id field and a size_id field as well as another field that''s a number, telling you how many of a certain design and size are available. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey thanks for that mate, it makes sense. I''ll give it a go. Does anyone know where i can go to read right up on the database relationship stuff? Cheers. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, I would recommend reading chapters 16, 17, and 18 of the "Agile Web Development with Rails 2ed (AWDwRv2)". This should give you a very good foundation from witch to build from. Good luck, -Conrad On Jan 3, 2008 8:06 PM, Darren Jeacocke <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey thanks for that mate, it makes sense. I''ll give it a go. > > Does anyone know where i can go to read right up on the database > relationship stuff? Cheers. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks lads, much appreciated! -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, i set up the relationship as Ryan suggested, and it looks as if it''s ready to go. now i''m making a nested unordered list so we can see [and edit] what designs and sizes we''ve got in stock. *Design1 *S [ 6] <---- text field *M [ ] *L [ 9] *XL [ 12] *Design2 *S [ 3] *M [ 8] *L [ 9] *XL [ 12] ........ can this all be done in the one form? i''m not sure how to grab the corresponding availability, and what if it hasn''t been created yet?? i thought something like: <% form_for(@availability) do |f| %> <ul> <% for design in @designs %> <li> <%=h design.name %> <ul> <% for size in @sizes %> <li><%= size.name %> [TEXT FIELD FOR NUM IN STOCK]</li> <% end %> </ul> </li> <% end %> </ul> <% end %> all the SQL is right there in my head! still trying to grasp the whole object oriented thing. Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
i can get <%= f.text_field :number %> to render a text field, just what i want, but it doesn''t know to use both design_id and size_id as foreign keys. <% form_for(@availability) do |f| %> <ul> <% for design in @designs %> <li> <%=h design.name %> <ul> <% for size in @sizes %> <li><%= size.name %> <%= f.text_field :number %></li> <% end %> </ul> </li> <% end %> </ul> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 Fri, 04 Jan 2008 05:06:51 +0100, Darren Jeacocke wrote:> Hey thanks for that mate, it makes sense. I''ll give it a go. > > Does anyone know where i can go to read right up on the database > relationship stuff? Cheers.I would be more than glad to share tips by e-mail (or here); I''m working on a design almost exactly like what you have :) -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 -~----------~----~----~----~------~----~------~--~---