NAME
Class::ReluctantORM::Relationship::HasLazy
SYNOPSIS
# Declare a column to be lazy
Pirate->has_lazy('diary');
# Now you have:
$pirate = Pirate->fetch_with_diary($pirate_id);
@bipeds = Pirate->fetch_by_leg_count_with_diary(2);
# Get info about the relationship
$rel = Pirate->relationships('diary');
$str = $rel->type(); # 'has_lazy';
$str = $rel->linked_class(); # undef;
$str = $rel->linking_class(); # 'Pirate';
@fields = $rel->local_key_fields(); # field in Pirate that is lazy-loaded
# by this relationship, always one
@fields = $rel->remote_key_fields(); # empty list
$int = $rel->join_depth(); # 0
# Class::ReluctantORM::SQL integration
@sql_cols = $rel->additional_output_sql_columns();
@cols = $rel->local_key_sql_columns();
@cols = $rel->remote_key_sql_columns(); # empty list
@empty = $rel->join_local_key_sql_columns(); # always empty for HasLazy
@empty = $rel->join_remote_key_sql_columns(); # always empty for HasLazy
DESCRIPTION
The HasLazy relationship permits a class to be loaded from the database without loading all of its columns. If a field is declared has_lazy, the column will not be fetched from the database unless it is explicitly mentioned in a fetch_deep 'with' clause.
Unlike other relationships, HasLazy does not link to another CRO class. Nor does it require a remote table, as it draws its data from the base table.
HasLazy relationships do not have inverse relationships.
BUILD_CLASS INTEGRATION
HasLazy also provides integration via the build_class method of Class::ReluctantORM. This is merely for convenience; behind the scenes, has_lazy will be called for you.
MyClass->build_class(%other_opts, %lazy_opts);
By providing either of these two options, you can automatically set up many Lazy columns quickly.
- lazy_fields
-
Optional array ref. List of fields that should be made Lazy. Mutually exclusive with non_lazy_fields.
- non_lazy_fields
-
Optional array ref. If provided, ALL fields are assumed to be lazy, EXCEPT those listed here and primary and foreign keys. Mutually exclusive with non_lazy_fields.
$class->has_lazy('field_name');
Indicates that the given field should be lazy-loaded, meaning that is not automatically fetched during a regular fetch.
You can cause the field to be fetched by using fetch_deep or calling $obj->fetch_FIELD().
The field will not appear on the 'essential_fields' list, but it will appear on the 'field_names' list.
Note that the value passed to has_lazy is a field name, not a column name; for some classes, they may be different. This is configured by passing a hashref as the value of the 'fields' option to build_class.
The accessor/mutator will behave similarly to a HasOne accessor, in that it will die on access if the value has not been fetched.
$str = $rel->type();
Returns 'has_lazy'.
$bool = $rel->is_has_lazy();
Returns true.
$int = $rel->join_depth();
Returns 0.
$str = $rel->join_type();
Returns 'NONE'
$int = $rel->lower_multiplicity()
Returns 0.
$int = $rel->upper_multiplicity()
Returns 0 - this is a relationship that doesn't link to another table.