I have model waypoint
with two attributes
And model route
that is no more than sorted array of waypoints with some additional text info. Some routes can have same waypoints, so I want to separate waypoints from routes.
What is the best way to store waypoints inside route?
I see several ways:
waypoint_ids
attribute of route
, but in such situation I will not be able to get route and all his waypoints in one SQL request, because waypoint ids will be hidden in serialized string.create some third model that have such arguments
Connect routes and waypoints with many-to-many association and store position of waypoint in route in position
attribute. But it seems to be over-complicated.
What is the best way for me in such situation?
I'd opt for the second option -- use a join table (RouteWaypoints) with something like acts_as_list so that you can retrieve the Route with all it's Waypoints correctly sorted. This isn't overkill -- the DB is really good at this stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With