Replies: 1 comment
-
I've done something similar, but not exactly the same. In my setup, the name of the related record doesn't change, so It works kind of like this (caching & error checking removed for simplicity): class DocSubmitted{
public function __get($name){
return ($name == 'Type') ? $this->retrieveTypeRecord() : return parent:__get($name);
}
private function retrieveTypeRecord(){
switch($this->doc_type){
case 'Assignment':
return Assignment::findFirst($this->doc_id);
case 'Task':
return Task::findFirst($this->doc_id);
}
}
} This works fine for the view, where you're just reading the information. It gets trickier when you're saving or setting |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I have a DB doc_submitted which has two columns doc_type and doc_id where doc_type can refer to any table viz: assignment or task or book and doc_id will have respective id.
Now I want to write relationship in the DocSubmitted Model so I can refer them in view as doc_submitted.Assignment.topic or doc_submitted.Task.date.
If I'm putting the condition it's always searching in reference model instead of parent model.
Beta Was this translation helpful? Give feedback.
All reactions