sgpatil / oriquent

Orientdb Eloquent driver for Laravel 5
MIT License
47 stars 15 forks source link

How to eager-load related edges/vertices? #40

Open CristianSitov opened 7 years ago

CristianSitov commented 7 years ago

By running simple queries with Model::find() or Model::where() I'm obtaining a collection with entities only, without the related objects/vertices.

"@type" => "d"
"@rid" => "#25:1"
"@version" => 3
"@class" => "Resources"
"uuid" => "116118d0-63d3-11e7-9fdd-4d775a1245c6"
"updated_at" => "2017-07-08 11:46:23"
"created_at" => "2017-07-08 11:46:23"
"out_has_classification_types" => array:1 [
  0 => "#42:0"
]
"out_has_notes" => array:1 [
  0 => "#39:0"
]
"@fieldTypes" => "updated_at=t,created_at=t,out_has_classification_types=g,out_has_notes=g"

How can I run a query that can pull a specific "branch", for eg., Resource > HasClassificationType > ClassificationType and Resource > HasNote > Description, all together?

CristianSitov commented 7 years ago

If I setup a relation like

public function hasClassificationType()
{
    return $this->hasOne(ResourceClassificationType::class, HasClassificationType::class);
}

then I get the following error

Type error: Argument 1 passed to Sgpatil\Orientdb\Query\Builder::modelAsNode() must be of the type array or null, string given, called in /vendor/sgpatil/oriquent/src/Sgpatil/Orientdb/Eloquent/Relations/HasOne.php on line 69
CristianSitov commented 7 years ago

The problem seems to be here:

// in Sgpatil/Orientdb/Eloquent/Relations/HasOne.php
$parentNode = $this->query->getQuery()->modelAsNode($this->parent->getTable());

while Query::modelAsNode() method says it only accepts arrays as seen here

 /* @param  array $labels
 * @return string
 */
public function modelAsNode(array $labels = null) {