Added Eloquent 2.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
47
laravel/database/eloquent/relationships/has_one.php
Normal file
47
laravel/database/eloquent/relationships/has_one.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user