I have the following model:
class Point < ActiveRecord::Base
...
has_one :next_point, class_name: "Point", foreign_key: "next_point_id"
belongs_to :previous_point, class_name: "Point", foreign_key: "next_point_id"
# It should return an array with the next remaining points
def next_remaining_points
end
end
How do I do a method that returns the next_point until the next_point is nil?
There is a simple recursive solution to this in your Ruby code, but be warned that this can execute a DB query for each call. You may be better off with a custom SQL query.