Class FlexiRecord::Reference
In: lib/flexirecord.rb
Parent: Object

Objects of this class are used to describe a reference between two tables. You can create and register them by calling FlexiRecord::BaseRecord.add_many_to_one_reference or FlexiRecord::RaseRecord.add_one_to_one_reference. For using many-to-many relationships you have to extend the class FlexiRecord::Relationship and create two connected ManyToOneReference‘s for that class by calling FlexiRecord::BaseRecord.add_connected_references.

Methods

Attributes

destination_class  [R]  Class, whose objects are referred by others.
destination_columns  [R]  Columns in the referred class, providing a unique or primary key.
dst_to_src_attr  [R]  Name (String) of the attribute in the destination class, which is referring to one or many objects of the source class.
source_class  [R]  Class, whose objects are referring to others.
source_columns  [R]  Columns in the referring class, providing the foreign key.
src_to_dst_attr  [R]  Name (String) of the attribute in the source class, which is referring to one object of the destination class.

Public Class methods

Returns a new reference object, describing a relation where objects of the ‘source_class’ refer to objects of the ‘destination_class’. The ‘column_info’ field describes the columns used for that reference. If the ‘column_info’ field is a string, the primary key is used in the destination class, and the primary key prefixed by the string given in ‘column_info’ is used as the foreign key in the source class. If ‘column_info’ is an array, it contains the columns in the source class, followed by the columns in the destination class. The field ‘src_to_dst_attr’ contains the name of the attribute in the source class, which is referring to one object of the destination class. The field ‘dst_to_src_attr’ contains the name of the attribute in the destination class, which is referring to one or many objects of the source class. After the reference has been created, reader, loader and setter functions are added to the ‘source_class’ and ‘destination_class’, to provide access to referenced and referring objects. This method is private, use one of the child classes OneToOneReference or ManyToOneReference, which get the same arguments, to generate references of a given type.

Public Instance methods

Connects two ManyToOneReference‘s to form a many-to-many relation. ‘other_reference’ is another Reference object (as returned by FlexiRecord::Reference.new, ‘own_attr’ is the attribute to be installed in the destination_class of this Reference object for accessing objects of the destination_class of the ‘other_reference’ object, and ‘other_attr’ is the attribute to be installed in the destination_class of the ‘other_reference’ object for accessing objects of the destination_class of this Reference object.

Returns true, if the object describes a many-to-one relation.

Returns true, if the object describes a one-to-one relation.

[Validate]