I have a somewhat complex relationship that I can’t seem to express
properly. I have a model that has a has_many relationship to itself.
The idea is that a customer has a “state” and the states have a
prescribed flow to the next state. The idea is that a customer who is
in a state of “good standing” can’t go directly to “blacklisted”
without first going through “probation” or “under review”.
There are two models…
class State < ActiveRecord::Base
has_many :from_state_flows, :class_name => ‘StateFlow’, :foreign_key
has_many :to_state_flows, :class_name => ‘StateFlow’, :foreign_key =>
class StateFlow < ActiveRecord::Base
belongs_to :from_state, :class_name => ‘State’, :foreign_key =>
belongs_to :to_state, :class_name => ‘State’, :foreign_key =>
I can’t get any “:through” relationship to work properly. The best I
have is this:
has_many :next_valid_states, :through => :to_state_flows, :source =>
I don’t really care if the solution is using a “through”. I just want
to get a list of the next valid set of states from the current state. I
can’t even figure out how to this through find() with an :include.
Any help is appreciated!