PHP Class lithium\data\model\Relationship

Inheritance: extends lithium\core\Object
Afficher le fichier Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Свойство Type Description
$_classes array Class dependencies.

Méthodes publiques

Méthode Description
__call ( string $name, array $args = [] ) : mixed Allows relationship configuration items to be queried by name as methods.
__construct ( array $config = [] ) : void Constructor. Constructs an object that represents a relationship between two model classes.
data ( string $key = null ) : mixed Returns the named configuration item, or all configuration data, if no parameter is given.
foreignKey ( $primaryKey ) : array Build foreign keys from primary keys array.
get ( object $object, array $options = [] ) : object Gets a related object (or objects) for the given object connected to it by this relationship.
query ( object $object ) : object Generates query parameters for a related object (or objects) for the given object connected to it by this relationship.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.

Méthodes protégées

Méthode Description
_init ( ) Initializes the Relationship object by attempting to automatically generate any values that were not provided in the constructor configuration.
_keys ( $keys ) Generates an array of relationship key pairs, where the keys are fields on the origin model, and values are fields on the lniked model.
_strategies ( ) Strategies used to query related objects, indexed by key.

Method Details

__call() public méthode

Allows relationship configuration items to be queried by name as methods.
public __call ( string $name, array $args = [] ) : mixed
$name string The name of the configuration item to query.
$args array Unused.
Résultat mixed Returns the value of the given configuration item.

__construct() public méthode

Constructor. Constructs an object that represents a relationship between two model classes.
public __construct ( array $config = [] ) : void
$config array The relationship's configuration, which defines how the two models in question are bound. The available options are: - `'name'` _string_: The name of the relationship in the context of the originating model. For example, a `Posts` model might define a relationship to a `Users` model like so: `public $hasMany = array('Author' => array('to' => 'Users'));` In this case, the relationship is bound to the `Users` model, but `'Author'` would be the relationship name. This is the name with which the relationship is referenced in the originating model. - `'key'` _mixed_: An array of fields that define the relationship, where the keys are fields in the originating model, and the values are fields in the target model. If the relationship is not defined by keys, this array should be empty. - `'type'` _string_: The type of relationship. Should be one of `'belongsTo'`, `'hasOne'` or `'hasMany'`. - `'from'` _string_: The fully namespaced class name of the model where this relationship originates. - `'to'` _string_: The fully namespaced class name of the model that this relationship targets. - `'link'` _string_: A constant specifying how the object bound to the originating model is linked to the object bound to the target model. For relational databases, the only valid value is `LINK_KEY`, which means a foreign key in one object matches another key (usually the primary key) in the other. For document-oriented and other non-relational databases, different types of linking, including key lists, database reference objects (such as MongoDB's `MongoDBRef`), or even embedding. - `'fields'` _mixed_: An array of the subset of fields that should be selected from the related object(s) by default. If set to `true` (the default), all fields are selected. - `'fieldName'` _string_: The name of the field used when accessing the related data in a result set. For example, in the case of `Posts hasMany Comments`, the field name defaults to `'comments'`, so comment data is accessed (assuming `$post = Posts::first()`) as `$post->comments`. - `'constraints'` _mixed_: A string or array containing additional constraints on the relationship query. If a string, can contain a literal SQL fragment or other database-native value. If an array, maps fields from the related object either to fields elsewhere, or to arbitrary expressions. In either case, _the values specified here will be literally interpreted by the database_. - `'strategy'` _\Closure_: An anonymous function used by an instantiating class, such as a database object, to provide additional, dynamic configuration, after the `Relationship` instance has finished configuring itself.
Résultat void

_init() protected méthode

Initializes the Relationship object by attempting to automatically generate any values that were not provided in the constructor configuration.
protected _init ( )

_keys() protected méthode

Generates an array of relationship key pairs, where the keys are fields on the origin model, and values are fields on the lniked model.
protected _keys ( $keys )

_strategies() protected méthode

Strategies used to query related objects, indexed by key.
protected _strategies ( )

data() public méthode

Returns the named configuration item, or all configuration data, if no parameter is given.
public data ( string $key = null ) : mixed
$key string The name of the configuration item to return, or `null` to return all items.
Résultat mixed Returns a single configuration item (mixed), or an array of all items.

foreignKey() public méthode

Build foreign keys from primary keys array.
public foreignKey ( $primaryKey ) : array
$primaryKey An array where keys are primary keys and values are the associated values of primary keys.
Résultat array An array where keys are foreign keys and values are the associated values of foreign keys.

get() public méthode

Gets a related object (or objects) for the given object connected to it by this relationship.
public get ( object $object, array $options = [] ) : object
$object object The object to get the related data for.
$options array Additional options to merge into the query to be performed, where applicable.
Résultat object Returns the object(s) for this relationship.

query() public méthode

Generates query parameters for a related object (or objects) for the given object connected to it by this relationship.
public query ( object $object ) : object
$object object The object to get the related data for.
Résultat object Returns the object(s) for this relationship.

respondsTo() public méthode

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
Résultat boolean Returns `true` if the method can be called, `false` otherwise.

Property Details

$_classes protected_oe property

Class dependencies.
protected array $_classes
Résultat array