![]() |
Entity - allowedFields add functionality - 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 - allowedFields add functionality (/showthread.php?tid=79985) |
Entity - allowedFields add functionality - maximusto - 08-29-2021 As per https://forum.codeigniter.com/forum-29.html I thought by adding $allowedFields to an entity that an Entity would behave similar to a Model. (Indeed I thought that defining $attributes was the same thing as defining $allowedFields in the context of an Entity.)
Indeed I think from a design perspective that when defining an Entity as per my understanding: Quote:"At its core, an Entity class is simply a class that represents a single database row." Therefore when we are defining fields using $attributes in an Entity shouldn't we effectively be setting the $allowedFields of that database row? I think a good implementation would be to have $eligibleFields for Entities and $allowedFields for Models where if $allowedFields is not blank that it takes precedence. (Typically where an Entity is defined as the $returnType of a Model then that is the place for fields to defined rather than at the model level.) Whats are your thoughts? RE: Entity - allowedFields add functionality - maximusto - 09-03-2021 (The $datamap functionality would also be very useful at the entity level so that it can be used standalone from model.) EDIT: ugh while playing further I set up the entity in error as: Code: use CodeIgniter\Entity; Instead of: Code: use CodeIgniter\Entity\Entity; I get that model functionality will need to work whether or not an entity is used ie. Model needs to retain functionality to define and transform output. However where an entity is defined then shouldn't this be where "row" definitions are provided??? When an entity is present then: Model is used for transformation / Entity is used for definition? Entities being reusable across models. ---ok enough whining to myself... this is how I extended the entity class to have similar functionality to allowedFields in Models... To utilise this in the Entity setup: PHP Code: <?php PHP Code: $jsinput = new \App\Entities\JSOutput(); Added a class EntityExt as an extension of Entity as follows: Code: <?php |