Added Eloquent 2.

Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
Taylor Otwell
2012-03-16 08:37:31 -05:00
parent 3de0d1af66
commit d6d667af90
9 changed files with 1308 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php namespace Laravel\Database\Eloquent\Relationships;
class Has_One extends Has_One_Or_Many {
/**
* Get the properly hydrated results for the relationship.
*
* @return Model
*/
public function results()
{
return parent::first();
}
/**
* Initialize a relationship on an array of parent models.
*
* @param array $parents
* @param string $relationship
* @return void
*/
public function initialize(&$parents, $relationship)
{
foreach ($parents as &$parent)
{
$parent->relationships[$relationship] = null;
}
}
/**
* Match eagerly loaded child models to their parent models.
*
* @param array $parents
* @param array $children
* @return void
*/
public function match($relationship, &$parents, $children)
{
$foreign = $this->foreign_key();
foreach ($children as $key => $child)
{
$parents[$child->$foreign]->relationships[$relationship] = $child;
}
}
}