Module: Dagnabit::Link::TransitiveClosureLinkModel

Defined in:
lib/dagnabit/link/transitive_closure_link_model.rb

Overview

Builds a model for transitive closure tuples.

The transitive closure model is generated inside the link class. Therefore, if your link model class was called Link, the transitive closure model would be named Link::(class name here). The name of the transitive closure model class is determined when the link class model is activated; see Dagnabit::Activation#acts_as_dag_link for more information.

Model class details

Construction details

The transitive closure model is constructed as a subclass of ActiveRecord::Base, not as a subclass of your link model class. The transitive closure model also acts as a dag link (via Dagnabit::Activation#acts_as_dag_link) and is configured using the same configuration options as your link model class.

This means:

  • The transitive closure tuple table and your link table must have the same column names for ancestor id/type and descendant id/type.

  • You will not be able to use any methods defined on your link model on the transitive closure model.

Available methods

The following class methods are available on transitive closure link models:

linking(a, b)

Returns all links (direct or indirect) linking a and b.

ancestor_type(type)

Behaves identically to the ancestor_type named scope defined in Dagnabit::Link::NamedScopes.

descendant_type(type)

Behaves identically to the descendant_type named scope defined in Dagnabit::Link::NamedScopes.

The following instance methods are available on transitive closure link models:

ancestor

Returns the ancestor of this link. Behaves identically to the ancestor association defined in Dagnabit::Link::Associations.

descendant

Returns the descendant of this link. Behaves identically to the descendant association defined in Dagnabit::Link::Associations.

Instance Attribute Summary collapse

Instance Attribute Details

#transitive_closure_classObject (readonly)

Returns the value of attribute transitive_closure_class.



54
55
56
# File 'lib/dagnabit/link/transitive_closure_link_model.rb', line 54

def transitive_closure_class
  @transitive_closure_class
end