# 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')
);
}
Show file
Open project: jpfuentes2/php-activerecord
Property | Type | Description | |
---|---|---|---|
$primary_key | |||
$valid_association_options | array |
|
Method | Description | |
---|---|---|
__construct ( array $options = [] ) : |
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, |
Method | Description | |
---|---|---|
set_keys ( $model_class_name, $override = false ) |
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 ) |
public __construct ( array $options = [] ) : |
||
$options | array | Options for the association |
return |
public build_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true ) | ||
$model | activerecord\Model |
public create_association ( activerecord\Model $model, $attributes = [], $guard_attributes = true ) | ||
$model | activerecord\Model |
public load_eagerly ( $models = [], $attributes = [], $includes, |
||
$table |
protected static array $valid_association_options | ||
return | array |