Laravel NeoEloquent эквивалент внутреннего присоединения - PullRequest
0 голосов
/ 07 февраля 2020

У меня есть этот график

enter image description here

Зеленые узлы - это ответы.

Темная роза - это вопрос, возможно, более одного.

Синий узел - это раздел, может быть больше одного.

И, наконец, узел розы - это вопросник.

И я скачал NeoEloquent от Vinelab, моя проблема в том, что мне нужно получить Вопросник, но я ничего не получаю.

Мои модели

Раздел

use Illuminate\Database\Eloquent\Model as NeoEloquent;
use App\Question;
use App\Questionnaire;

class Section extends \NeoEloquent
{
    protected $label = "Section";
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
      'title'
    ];

    public function questionnaire(){
      return $this->hasOne('App\Questionnaire','IS_IN');
    }
}

Вопрос

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Model as NeoEloquent;
use App\Answer;
use App\Section;

class Question extends \NeoEloquent
{
    protected $label = 'Question'; //Node name
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'question','type'
    ];
    public function section(){
      return $this->hasOne('App\Section','IS_IN');
    }
}

Ответ

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Model as NeoEloquent;
use App\Question;

class Answer extends \NeoEloquent
{
     protected $label = 'Answer';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'content'
    ];
    public function question(){
      return $this->hasOne('App\Question','IS_IN');
    }
}

Я нашел несколько примеров получения родитель от ребенка, но дело в том, что мне нужно создать API, который получает ID анкеты и должен вернуть все дочерние узлы.

Я пробовал что-то подобное.

$trying = Section::whereHas('questionnaire',function($query) use($id){
        $query->where('id','=',$id);
      })->get();

Но это просто приносит мне родительский вопросник, но не секрет, еще одно решение, которое я понял, - это получить все узлы, make и arra у foreach и некоторые если.

Эквивалент Cypher

match (q:Questionnarie)<-[x]-(y:Section)<-[t]-(n:Question)<-[e]-(p:Answer) where ID(q) = 83 return q,x,y,t,n,e,p

...