PHP Class ActiveRecord\HasMany

# 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') ); }
See also: http://www.phpactiverecord.org/guides/associations
See also: valid_association_options
Inheritance: extends AbstractRelationship
Show file Open project: jpfuentes2/php-activerecord

Protected Properties

Property Type Description
$primary_key
$valid_association_options array
  • 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

Public Methods

Method Description
__construct ( array $options = [] ) : HasMany Constructs a {@link HasMany} relationship.
build_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true )
create_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true )
load ( activerecord\Model $model )
load_eagerly ( $models = [], $attributes = [], $includes, Table $table )

Protected Methods

Method Description
set_keys ( $model_class_name, $override = false )

Private Methods

Method Description
get_foreign_key_for_new_association ( activerecord\Model $model ) : array Get an array containing the key and value of the foreign key for the association
inject_foreign_key_for_new_association ( activerecord\Model $model, &$attributes )

Method Details

__construct() public method

Constructs a {@link HasMany} relationship.
public __construct ( array $options = [] ) : HasMany
$options array Options for the association
return HasMany

build_association() public method

public build_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true )
$model activerecord\Model

create_association() public method

public create_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true )
$model activerecord\Model

load() public method

public load ( activerecord\Model $model )
$model activerecord\Model

load_eagerly() public method

public load_eagerly ( $models = [], $attributes = [], $includes, Table $table )
$table Table

set_keys() protected method

protected set_keys ( $model_class_name, $override = false )

Property Details

$primary_key protected property

protected $primary_key

$valid_association_options protected static property

  • 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
protected static array $valid_association_options
return array