I am new to RoR, so I will apologize in advance. However, I am creating an mapping system with the Google API. So I have a model called Routes and a model called Locations. These are related in the fact that Routes have a start and end Location. Yet, I can''t determine the relationship to use. So... Idea 1: HABTM relationship, and adding a column to the join table for start/end. But that "feels wrong". Idea 2: Add options on a has_one relationship to map it accordingly. Idea 3: Something I haven''t thought of... I don''t know. Again, I''m new. Any direction would be appreciated. Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sent from my iPhone On 27 Sep 2008, at 17:18, Jason <mccreary.jason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am new to RoR, so I will apologize in advance. However, I am > creating an mapping system with the Google API. So I have a model > called Routes and a model called Locations. These are related in the > fact that Routes have a start and end Location. Yet, I can''t determine > the relationship to use. So... >Sounds to me like a route would have two belongs_to, one for the start and one for the end. Another way (which may or may not be relevant) would be for routes to has_many locations through waypoints: the join table would have a column specifying the order and would define the locations through which the route passes (of which start and end are just special cases) Fred> Idea 1: HABTM relationship, and adding a column to the join table for > start/end. But that "feels wrong". > Idea 2: Add options on a has_one relationship to map it accordingly. > Idea 3: Something I haven''t thought of... > > I don''t know. Again, I''m new. Any direction would be appreciated. > > Thanks, > Jason > >--~--~---------~--~----~------------~-------~--~----~ 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 understand what you are suggesting. However, which way is "better" practice? Should I use the two relationships, or one with a join table that contains the extra column. Can anyone provide a more specific solution.. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2008/9/29 Jason <mccreary.jason-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > I understand what you are suggesting. However, which way is "better" > practice? Should I use the two relationships, or one with a join table > that contains the extra column.I am new to rails, but very old in databases: If a route has two and will never have more than two nor less than two, you have to create two relationships, one called begin and other called end. Else, you have to create a table HABTM, where one route describes the full stack of relationships (with some kind of sorted-by). Regards, -- Rodrigo Fuentealba http://www.thecodekeeper.net/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Cool. Again, this is what I figured. If I go the two relationships in routes, what type of relationship is this... belongs_to? So I would write something like the following: class Route belongs_to :start, :class_name => ''Location'', :foreign_key => "start_location" belongs_to :end, :class_name => ''Location'', :foreign_key => "end_location" ... ?? On Sep 29, 8:32 pm, "Rodrigo Fuentealba" <the.code.kee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 2008/9/29 Jason <mccreary.ja...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > I am new to rails, but very old in databases: > > If a route has two and will never have more than two nor less than > two, you have to create two relationships, one called begin and other > called end. Else, you have to create a table HABTM, where one route > describes the full stack of relationships (with some kind of > sorted-by). > > Regards, > > -- > Rodrigo Fuentealbahttp://www.thecodekeeper.net/--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---