Doubts about relationship between Rails tables

1

Hello, I am a beginner in Rails, (setting up my first system) and I have two doubts about relationship between tables:

1.) I have a Line template with the source and destination attributes that should reference another Local , ie Line has a source attribute that is a local and another destination attribute that is another location, how do I make this association?

2.) Line represents a route between one place and another. In addition to the points of origin and destination, the line passes on several waypoints when it is going (origin> destination), and so many when it is returning (destination> origin). Each reference point of this is a "referenced" location, which in addition to the attributes inherited from Location must have a "distance" information, ie Line, Direction One, after 20 minutes it passes in Location x.

Looking at the relationship between the objects (if you facilitate the understanding would have something like this):

  • Location {description: string}
  • Extends Reference Local {distance: integer}
  • Line {source: Local, destination: Local, referencesID: [Reference], referencesVolt: [References]}

More like creating the templates to represent this? bold text

    
asked by anonymous 03.07.2015 / 01:26

1 answer

1

First you have a Line entity that has several Local entities, and if a Location belongs to only one Line you will have a Line that belongs to a Location.

According to the same entity Line has multiple entities Reference

class Linha
  has_many :locais
  has_many :referencia 
end

class Local
  belongs_to :linha
end

class Referencia
  belongs_to :linha
end

References can have attributes that indicate the position next to the places, so you can calculate the value of the distance between references and / or places.

Any doubt about relationships the guides is an excellent reference: link

    
09.07.2015 / 19:49