# Add relationships to a ReluctantORM Class Pirate->has_one('Ship'); # Now you have: $pirate = Pirate->fetch_with_ship($pirate_id); @bipeds = Pirate->fetch_by_leg_count_with_ship(2); # Get info about the relationship $rel = Pirate->relationships('ship'); $str = $rel->type(); # 'has_one'; $str = $rel->linked_class(); # 'Ship'; $str = $rel->linking_class(); # 'Pirate'; @fields = $rel->local_key_fields(); # fields in Pirate that link to Ship @fields = $rel->remote_key_fields(); # array of fields in Ship that link to Pirate $int = $rel->join_depth(); # 1 # Class::ReluctantORM::SQL integration @sql_cols = $rel->additional_output_sql_columns(); @cols = $rel->local_key_sql_columns(); @cols = $rel->remote_key_sql_columns(); @empty = $rel->join_local_key_sql_columns(); # always empty for HasOne @empty = $rel->join_remote_key_sql_columns(); # always empty for HasOne
Describes a (possibly optional) relationship between two classes/tables.
The local table should have a column (or columns) that act as foreign keys into the remote table. An accessor/mutator wil be created that provides access to the related object.
Additionally, a new constructor is created, named $class->fetch_with_METHOD. This constructor has the special feature that it performs an outer join and pre-fetches the named object. Finally, additional constructors named $class->fetch_by_ATTRIBUTE_with_METHOD will also be available via AUTOLOAD.
In the first form, OtherClass is taken to be the 'class' argument, and all other arguments are determined from that.
The name of the remote ReluctantORM class.
The name of the foreign key column (or columns) in the local table. Optional - default is OtherClass->primary_key_columns().
The name of the foreign key column (or columns) in the remote table. Optional - default is OtherClass->primary_key_columns().
The name of the accessor/mutator method to be created. Optional - default is the lowercased and underscore-spaced version of the class name of OtherClass.
Deprecated synonym for local_key.
The mutator will set the corresponding local key column.
The accessor will display some behavior intended to help with scalability. If the value has already been fetched, it will be returned normally. If a trip to the database would be required, the method dies with an Class::ReluctantORM::Exception::Data::FetchRequired. You can then actually fetch the value using $instance->fetch_METHOD .
Returns 'LEFT OUTER'