Strict model: Add new field at runtime #224

Closed
opened 2021-03-09 02:39:18 +00:00 by jamie · 3 comments
jamie commented 2021-03-09 02:39:18 +00:00 (Migrated from git.hazaar.io)

I have an instance where I want to add a new field at runtime. Normally this isn't allowed as it goes against the principles of strict models in the the strict part is that it's supposed to restrict what can be added to a model and the data type. To do this, we need to define the field and it's type.

However it should be OK to add a new field definition at runtime. The case I'm thinking of is using DBI to get a row from a table using Hazaar\Table::findOneRow() which returns a Hazaar\DBI\Row object which itself extends Hazaar\Model\Strict and automatically defines all the fields in the model using the returned columns, including their type and any custom features/functions for those types that are provided by the row class. In a REST API, I want to return this row as is, allowing the Row class to do it's thing, but I want to add a field to the returned object (in this case, a URL).

I have an instance where I want to add a new field at runtime. Normally this isn't allowed as it goes against the principles of strict models in the the _strict_ part is that it's supposed to restrict what can be added to a model and the data type. To do this, we need to define the field and it's type. However it should be OK to add a new field definition at runtime. The case I'm thinking of is using **DBI** to get a row from a table using `Hazaar\Table::findOneRow()` which returns a `Hazaar\DBI\Row` object which itself extends `Hazaar\Model\Strict` and automatically defines all the fields in the model using the returned columns, including their type and any custom features/functions for those types that are provided by the row class. In a REST API, I want to return this row as is, allowing the Row class to do it's thing, but I want to add a field to the returned object (in this case, a URL).
jamie commented 2021-03-09 02:39:32 +00:00 (Migrated from git.hazaar.io)

created merge request !114 to address this issue

created merge request !114 to address this issue
jamie commented 2021-03-09 02:39:32 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !114

mentioned in merge request !114
jamie commented 2021-03-09 02:41:48 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 8a5eacbdb2d743d0fd5f4b944f3ef406f7d8d01f

mentioned in commit 8a5eacbdb2d743d0fd5f4b944f3ef406f7d8d01f
jamie (Migrated from git.hazaar.io) closed this issue 2021-03-09 02:41:48 +00:00
jamie self-assigned this 2025-09-04 01:15:28 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#224
No description provided.