Laravel NeoEloquent equivalent to Inner Join

138 Views Asked by At

I have this Graph

enter image description here

The green Nodes are Answers.

The dark rose node is Question, there could be more than one.

The Blue node is a section, there could be more than one.

And finally the rose node is the questionnaire.

And I've downloaded NeoEloquent from Vinelab, my problem is that I have to get a Questionnaire, but I'm getting nothing from there.

My Models Are

Section

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');
    }
}

Question

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');
    }
}

Answer

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');
    }
}

I've found some examples getting the parent from the child but the thing is that I have to make an API that gets Questionnaire ID and have to return all the children nodes.

I've tried something like this.

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

But this just brings me the parent questionnaire, but no the secction, another solution I've realized was to get all nodes and make and array by a foreach and some if.

Cypher equivalent

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

0

There are 0 best solutions below