What would be the right (Rails) way to have one model with both a has_many and a has_one relationship? In my case, I want my Device model to keep track of both its current location and all of its previous locations.
This is my attempt and it is functional but is there a better way?
Models
class Location < ActiveRecord::Base
belongs_to :device
end
class Device < ActiveRecord::Base
has_many :locations # all previous locations
belongs_to :location # current location
end
Note that all @device.locations, @device.previous_locations, and @device.current_location will return ActiveRecord::Relation