AbstractRelationship
   |
   --HasMany

Child classes:

HasOne
One-to-one relationship.

Class Details

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')
     );
 }

        


Class Variables

protected mixed $primary_key
protected static array $valid_association_options = array('primary_key', 'order', 'group', 'having', 'limit', 'offset', 'through', 'source')

Valid options to use for a HasMany relationship.

  • limit/offset: limit the number of records
  • primary_key: name of the primary_key of the association (defaults to "id")
  • group: GROUP BY clause
  • order: ORDER BY clause
  • through: name of a model


Class Methods

public HasMany __construct ( [ array $options = array()] )

Constructs a HasMany relationship.

  • array $options - Options for the association
public void build_association ( Model $model , [ $attributes = array()] )
  • Model $model -
  • $attributes -
public void create_association ( Model $model , [ $attributes = array()] )
  • Model $model -
  • $attributes -
public void load ( Model $model )
public void load_eagerly ( [ $models = array()] , [ $attributes = array()] , $includes , Table $table )
  • $models -
  • $attributes -
  • $includes -
  • Table $table -
protected void set_keys ( $model_class_name , [ $override = false] )
  • $model_class_name -
  • $override -