Skip to content

Commit

Permalink
Update method belongsTo
Browse files Browse the repository at this point in the history
Update method belongsTo
  • Loading branch information
code-and-code committed May 9, 2017
1 parent de4121f commit bc79a67
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ public function hasMany($class)
return $result;
}

public function belongsTo($class)
public function belongsTo($class,$column = null,$id = null)
{
$class = new $class();
$column = $this->columnRelationship($this);
$result = $class->where($column,'=',$this->id)->first();
(is_null($column)) ? $column = $this->columnRelationship($this) : $column = $column;
(is_null($id)) ? $id = $this->id : $id = $this->$id;

$result = $class->where($column,'=',$id)->first();

return $result;
}

Expand Down

0 comments on commit bc79a67

Please sign in to comment.