Child classes:
- HasMany
- One-to-many relationship.
- BelongsTo
- Belongs to relationship.
Class Details
Abstract class that all relationships must extend from.
- see: http://www.phpactiverecord.xyz/guides/associations
- abstract:
Class Variables
public string $attribute_name
Name to be used that will trigger call to the relationship.
public string $class_name
Class name of the associated model.
public string $foreign_key = array()
Name of the foreign key.
protected array $options = array()
Options of the relationship.
protected boolean $poly_relationship = false
Is the relationship single or multi.
protected static array $valid_association_options = array('class_name', 'class', 'foreign_key', 'conditions', 'select', 'readonly')
List of valid options for relationships.
Class Methods
public mixed __construct ( [ array $options = array()] )
Constructs a relationship.
- array $options - Options for the relationship (see valid_association_options)
public string construct_inner_join_sql ( Table $from_table , [ bool $using_through = false] , [ string $alias = null] )
Creates INNER JOIN SQL for associations.
- Table $from_table - the table used for the FROM SQL statement
- bool $using_through - is this a THROUGH relationship?
- string $alias - a table alias for when a table is being joined twice
- return: SQL INNER JOIN fragment
protected void create_conditions_from_keys ( Model $model , [ $condition_keys = array()] , [ $value_keys = array()] )
- Model $model -
- $condition_keys -
- $value_keys -
protected void get_table ( )
public bool is_poly ( )
What is this relationship's cardinality?
public void load ( Model $model )
This will load the related model data.
- Model $model - The model this relationship belongs to
- abstract:
protected void merge_association_options ( $options )
- $options -
protected void query_and_attach_related_models_eagerly ( Table $table , $models $models , $attributes $attributes , [ $includes $includes = array()] , [ $query_keys $query_keys = array()] , [ $model_values_keys $model_values_keys = array()] )
Eagerly loads relationships for $models.
- Table $table -
- $models $models - array of model objects
- $attributes $attributes - array of attributes from $models
- $includes $includes - array of eager load directives
- $query_keys $query_keys - -> key(s) to be queried for on included/related table
- $model_values_keys $model_values_keys - -> key(s)/value(s) to be used in query from model which is including
This method takes an array of models, collects PK or FK (whichever is needed for relationship), then queries the related table by PK/FK and attaches the array of returned relationships to the appropriately named relationship on $models.
protected void set_class_name ( $class_name )
- $class_name -
protected void set_inferred_class_name ( )
Infers the $this->class_name based on $this->attribute_name.
Will try to guess the appropriate class by singularizing and uppercasing $this->attribute_name.
protected void unset_non_finder_options ( $options )
- $options -