Model/Database Relationship? |
The only thing I can think about right now for this setup is something along the lines of this (creating a new method in the main item model, and linking all the other models together manually) really replacing the use of find() elsewhere.
public function getItem($id) { $post = $this->find($id); $files = new \App\Models\PostFiles(); $post->file = $files->where(['post_id'=>$id,'primary'=>'Y'])->first(); $images = new \App\Models\PostImages(); $post->image = $images->where(['post_id'=>$id,'primary'=>'Y'])->first(); $desc = new \App\Models\PostDescriptions(); $post->description = $desc->where(['post_id'=>$id,'primary'=>'Y'])->first(); return $post; } This way I can just call "$post->getItem(id)" and use the other tables for my relationship "$post->image->location" etc |
Messages In This Thread |
Model/Database Relationship? - by idealcastle - 07-22-2016, 03:06 PM
RE: Model/Database Relationship? - by idealcastle - 07-22-2016, 03:29 PM
RE: Model/Database Relationship? - by JayAdra - 07-22-2016, 06:25 PM
RE: Model/Database Relationship? - by idealcastle - 07-23-2016, 05:56 AM
RE: Model/Database Relationship? - by arma7x - 07-23-2016, 06:28 AM
RE: Model/Database Relationship? - by kilishan - 07-24-2016, 09:52 PM
RE: Model/Database Relationship? - by idealcastle - 08-01-2016, 07:48 AM
RE: Model/Database Relationship? - by kilishan - 08-01-2016, 07:58 AM
|