Entity models? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: Entity models? (/showthread.php?tid=61377) Pages:
1
2
|
RE: Entity models? - PaulD - 04-20-2015 I vote No. But bow to greater experience in the matter. I use the models to represent areas of concern, not tables. I tried on one site to have one model per table but it just didn't work for me. Where do you put queries that get from more than one table, or queries that update several tables? Even the way I do it now sometimes leaves me scratching my head about which model to put the function in. I think the role of models is very dependent on the nature of the site. One of the things I truly love about CI is that I can work in any way that suits me with it. I would not want to lose that even if it means that I can work NOT following best practice if I choose to. (I admit also to sometimes putting queries in controllers for quick solutions and small sites). Paul. RE: Entity models? - kilishan - 06-09-2015 After working on a new project and thinking about this some more, I would have to vote 'Yes'. I so wish I had something like this right now. RE: Entity models? - RWCH - 06-12-2015 (04-16-2015, 11:31 PM)jlp Wrote: What I was suggesting has nothing to do with ORM. It is just a way of having the existing model be able to use something other than stdClass. The "entity model" would represent one record in the returned result set, and could be whatever you want it to be. Properties would be injected into such an object the same way they are in a stdClass object in a result set, but we would then have a way to do something entity-specific with such objects. So if I understand it right, you want the CodeIgniter DB classes be able to return specific objects (which you call "entiry models" here) and not just collections (read "arrays"). I guess that would be okay... but the returned objects would be different from my domain objects, like the objects rerturned by mysql_fetch_object (standard PHP) are also different from my domain objects. Wouldn't that make your "enity models" DTO's (data transfer objects)? If that is true, I still have to map them to my domain objects. In that case the value of using these kind of classes seems limited. Or can I specify that the returned objects must be of the type of my domain object? That would be cool. Is that possible? Do I understand it right and are my objections valid? Please explain what the benefits of entity models are ... and how they (could) work Thanks RE: Entity models? - mwhitney - 06-15-2015 (06-12-2015, 07:36 AM)RWCH Wrote:(04-16-2015, 11:31 PM)jlp Wrote: What I was suggesting has nothing to do with ORM. It is just a way of having the existing model be able to use something other than stdClass. The "entity model" would represent one record in the returned result set, and could be whatever you want it to be. Properties would be injected into such an object the same way they are in a stdClass object in a result set, but we would then have a way to do something entity-specific with such objects. I believe that would be the point of such a change. The entity model would be your domain object while the existing model acts, more or less, as a mechanism for retrieving domain objects. This might be similar to using $this->db->custom_result_object($class_name) instead of using $this->db->result() or $this->db->result_array() when returning database results from your model. |