Module: ActsAsJoinable::Core::InstanceMethods

Defined in:
lib/acts_as_joinable/core.rb

Instance Method Summary collapse

Instance Method Details

#child_relationships_for(conditions = {}) ⇒ Object



414
415
416
417
418
# File 'lib/acts_as_joinable/core.rb', line 414

def child_relationships_for(conditions = {})
  child_relationships.select do |relationship|
    relationship_matches?(relationship, conditions)
  end.uniq_by(&:child_id)
end

#destroy_relationshipsObject



391
392
393
394
395
396
397
398
399
# File 'lib/acts_as_joinable/core.rb', line 391

def destroy_relationships
  #conditions = %Q|(`relationships`.parent_type IN ("#{self.class.name}","#{self.class.base_class.name}") AND `relationships`.parent_id = #{self.id}) OR (`relationships`.child_type IN ("#{self.class.name}","#{self.class.base_class.name}") AND `relationships`.child_id = #{self.id})|
  classes = [self.class.name, self.class.base_class.name].compact.uniq
  #relationship_table_name = Relationship.quoted_table_name
  #conditions = %Q|(#{relationship_table_name}.parent_type IN (#{classes}) AND #{relationship_table_name}.parent_id = #{self.id}) OR (#{relationship_table_name}.child_type IN (#{classes}) AND #{relationship_table_name}.child_id = #{self.id})|
  #Relationship.delete_all(conditions)
  Relationship.delete_all(:parent_type => classes, :parent_id => self.id)
  Relationship.delete_all(:child_type => classes, :child_id => self.id)
end

#parent_relationships_for(conditions = {}) ⇒ Object



408
409
410
411
412
# File 'lib/acts_as_joinable/core.rb', line 408

def parent_relationships_for(conditions = {})
  parent_relationships.select do |relationship|
    relationship_matches?(relationship, conditions)
  end.uniq_by(&:parent_id)
end

#relationship_matches?(relationship, conditions) ⇒ Boolean

Returns:

  • (Boolean)


401
402
403
404
405
406
# File 'lib/acts_as_joinable/core.rb', line 401

def relationship_matches?(relationship, conditions)
  return false if conditions[:parent_type] && !Array(conditions[:parent_type]).include?(relationship.parent_type)
  return false if conditions[:child_type] && !Array(conditions[:child_type]).include?(relationship.child_type)
  return false if conditions[:context] && !Array(conditions[:context]).include?(relationship.context)
  true
end

#write_join_attribute(name, value) ⇒ Object



387
388
389
# File 'lib/acts_as_joinable/core.rb', line 387

def write_join_attribute(name, value)
  
end