app/models/mixins/relationship_mixin.rb
# Returns an existing relationship if found, otherwise creates a new one
#   If parent_rel is passed, also connects the returned relationship to the
#   parent, possibly delinking from an existing parent.
Returns an existing relationship if found, otherwise creates a new one
If parent_rel is passed, also connects the returned relationship to the
parent, possibly delinking from an existing parent.
Returns an existing relationship if found otherwise creates a new one If parent_rel is passed also connects the returned relationship to the parent possibly delinking from an existing parent .
def init_relationship(parent_rel = nil)
    rel = relationship
    if rel.nil?
      rel = add_relationship(parent_rel)
    elsif !parent_rel.nil?
      rel.update_attribute(:parent, parent_rel)
    end
    rel
  end
def init_relationship ( parent_rel = nil ) rel = relationship if rel . nil? rel = add_relationship ( parent_rel ) elsif ! parent_rel . nil? rel . update_attribute ( :parent , parent_rel ) end rel end
Returns an existing relationship if found, otherwise creates a new one
If parent_rel is passed, also connects the returned relationship to the
parent, possibly delinking from an existing parent.
Returns an existing relationship if found otherwise creates a new one If parent_rel is passed also connects the returned relationship to the parent possibly delinking from an existing parent .
parent_rel
<not_specific>