Very simple question: Laravel eloquent docs specify that the morphTo function defines a polymorphic, inverse one-to-one or many relationship. Is there anyway (laravel forks maybe ?) to create a polymorphic, non-inverse one-to-one or many relationship, Without doing it myself and diving in Laravel's Eloquent relationships code ?
To be clear: I want to do something like:
class Answer extends Eloquent {
protected $fillable = array('answer_id', 'answer_type');
public function answers() {
return $this->straightMorphTo('answer_id', 'answer_type', 'id');
}
}
class AnswerFirst extends Eloquent {
protected $fillable = array('id', 'text');
public function answers() {
return $this->belongsTo('Answer');
}
}
class AnswerSecond extends Eloquent {
protected $fillable = array('id', 'number');
public function answers() {
return $this->belongsTo('Answer');
}
}
//
// Answer
// ------------------------------------
// answer_id | answer_type |
// ------------------------------------
// 1 | AnswerFirst |
// 2 | AnswerSecond |
// ------------------------------------
//
// AnswerFirst
// ------------------------------------
// id | text |
// ------------------------------------
// 1 | 1rst part |
// 1 | 2nd part |
// ------------------------------------
//
// AnswerSecond
// ------------------------------------
// id | number |
// ------------------------------------
// 2 | 1 |
// 2 | 2 |
// ------------------------------------
//
And then, Answer::with('answers')->find(2) should return
{
id:'2',
answer_type:'AnswerSecond',
answers: [
{id:'2',number:'1'},
{id:'2',number:'2'},
]
}