我有这个图表
绿色节点是答案。
暗玫瑰节点是问题,可能不止一个。
蓝色节点是一个部分,可能不止一个。
最后玫瑰节点是问卷。
我已经从 Vinelab 下载了NeoEloquent,我的问题是我必须得到一份问卷,但我从那里什么也得不到。
我的模特是
部分
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');
}
}
我找到了一些从子节点获取父节点的示例,但问题是我必须创建一个获取问卷 ID 并且必须返回所有子节点的 API。
我试过这样的事情。
$trying = Section::whereHas('questionnaire',function($query) use($id){
$query->where('id','=',$id);
})->get();
但这只是给我带来了父问卷,但没有部分,我意识到的另一个解决方案是获取所有节点并通过 foreach 和一些 if 进行制作和排列。
密码等效
match (q:Questionnarie)<-[x]-(y:Section)<-[t]-(n:Question)<-[e]-(p:Answer) where ID(q) = 83 return q,x,y,t,n,e,p