HasMany
class HasMany extends AbstractRelationship (View source)
One-to-many relationship.
Table: people
Primary key: id
Foreign key: school_id
class Person extends ActiveRecord\Model {}
Table: schools
Primary key: id
class School extends ActiveRecord\Model { static $has_many = array( array('people') ); });
Example using options:
class Payment extends ActiveRecord\Model {
static $belongs_to = array(
array('person'),
array('order')
);
}
class Order extends ActiveRecord\Model { static $has_many = array( array('people', 'through' => 'payments', 'select' => 'people.*, payments.amount', 'conditions' => 'payments.amount < 200') ); }
Properties
string | $attribute_name | Name to be used that will trigger call to the relationship. | from AbstractRelationship |
string | $class_name | Class name of the associated model. | from AbstractRelationship |
string | $foreign_key | Name of the foreign key. | from AbstractRelationship |
protected array | $options | Options of the relationship. | from AbstractRelationship |
protected boolean | $poly_relationship | Is the relationship single or multi. | from AbstractRelationship |
static protected array | $valid_association_options | Valid options to use for a {@link HasMany} relationship. | |
protected | $primary_key |
Methods
Constructs a {@link HasMany} relationship.
Eagerly loads relationships for $models.
Creates a new instance of specified {@link Model} with the attributes pre-loaded.
Creates a new instance of {@link Model} and invokes save.
Infers the $this->class_name based on $this->attribute_name.
No description
Creates INNER JOIN SQL for associations.
No description
Details
at line 457
__construct($options = array())
Constructs a {@link HasMany} relationship.
in AbstractRelationship at line 99
protected
get_table()
in AbstractRelationship at line 109
bool
is_poly()
What is this relationship's cardinality?
in AbstractRelationship at line 129
protected void
query_and_attach_related_models_eagerly(Table $table, $models, $attributes, $includes = array(), $query_keys = array(), $model_values_keys = array())
Eagerly loads relationships for $models.
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.
at line 559
build_association(Model $model, $attributes = array(), $guard_attributes = true)
Creates a new instance of specified {@link Model} with the attributes pre-loaded.
at line 580
create_association(Model $model, $attributes = array(), $guard_attributes = true)
Creates a new instance of {@link Model} and invokes save.
in AbstractRelationship at line 242
protected
append_record_to_associate(Model $associate, Model $record)
in AbstractRelationship at line 254
protected
merge_association_options($options)
in AbstractRelationship at line 265
protected
unset_non_finder_options($options)
in AbstractRelationship at line 283
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.
in AbstractRelationship at line 289
protected
set_class_name($class_name)
in AbstractRelationship at line 303
protected
create_conditions_from_keys(Model $model, $condition_keys = array(), $value_keys = array())
in AbstractRelationship at line 331
string
construct_inner_join_sql(Table $from_table, bool $using_through = false, string $alias = null)
Creates INNER JOIN SQL for associations.