Log message #4267484

# At Username Text
# Jul 12th 2021, 19:57 tyler.adam.lazenby well this way works for now
# Jul 12th 2021, 19:56 kevin.pfeifer or jsut a Table method if its just for 1 table/entity type
# Jul 12th 2021, 19:56 kevin.pfeifer you could make a behavior which populates you empty entites with a given set of default data
# Jul 12th 2021, 19:55 kevin.pfeifer well the default `newEmptyEntity` method just creates a new entity object of whatever is given to it so no default data there
# Jul 12th 2021, 19:55 cnizzardini there are times where automated jobs or events trigger stuff though :man-shrugging:
# Jul 12th 2021, 19:54 cnizzardini or doing things
# Jul 12th 2021, 19:54 cnizzardini its not the worst thing, generally you only want a single source for creating things
# Jul 12th 2021, 19:53 kevin.pfeifer maybe some other MVC gurus can give you other insights of why this needs to be done this way
# Jul 12th 2021, 19:52 cnizzardini there is no way to call entity->isNew() or whatever from there to isolate it to new creations
# Jul 12th 2021, 19:52 kevin.pfeifer :)
# Jul 12th 2021, 19:52 kevin.pfeifer It would also be nice if the cakephp book would “remember” where I was when switching from 3 to 4 Like https://book.cakephp.org/3/en/orm/table-objects.html and then clicking on the 4.x link at the top right should lead me to https://book.cakephp.org/4/en/orm/table-objects.html
# Jul 12th 2021, 19:52 tyler.adam.lazenby I just hate it
# Jul 12th 2021, 19:52 tyler.adam.lazenby Kevin you might be right here
# Jul 12th 2021, 19:51 tyler.adam.lazenby gosh dang it
# Jul 12th 2021, 19:51 tyler.adam.lazenby lets see if update changes the value
# Jul 12th 2021, 19:50 tyler.adam.lazenby hmmm
# Jul 12th 2021, 19:50 tyler.adam.lazenby except
# Jul 12th 2021, 19:50 cnizzardini cool, again, id test various scenarios with that
# Jul 12th 2021, 19:50 tyler.adam.lazenby its used in API calls
# Jul 12th 2021, 19:50 tyler.adam.lazenby Because this value should never be user created
# Jul 12th 2021, 19:49 tyler.adam.lazenby before marshall works here
# Jul 12th 2021, 19:49 kevin.pfeifer behaviors are just re-usable model logic which can be applied to multiple models like components are to controllers
# Jul 12th 2021, 19:48 kevin.pfeifer I am not aware of what the “best practice” for that would be Its just that I am aware of either the controller method or the template (set input value) method
# Jul 12th 2021, 19:48 cnizzardini behavior is another way to try, thats how the timestamp stuff works I believe
# Jul 12th 2021, 19:47 cnizzardini kevins approach might be best, its more obvious, idk, you have options though
# Jul 12th 2021, 19:47 tyler.adam.lazenby I am testing it
# Jul 12th 2021, 19:47 cnizzardini haven't actually tried using beforeMarshal for this purpose
# Jul 12th 2021, 19:46 cnizzardini or overwrite an existing value because it was not present in the update
# Jul 12th 2021, 19:46 cnizzardini wouldn't want to default to a value on an update if the user supplied a value
# Jul 12th 2021, 19:46 kevin.pfeifer in my opinion
# Jul 12th 2021, 19:46 kevin.pfeifer i understand why setting default values in the models seems fine but depending on your model/data you could run in the use case, that you need different default values depending on the situation Therefore it would be better to create an empty entity, patch the default value and then patch the input data
# Jul 12th 2021, 19:46 cnizzardini id do some testing around create vs update with that though
# Jul 12th 2021, 19:45 cnizzardini https://book.cakephp.org/4/en/orm/saving-data.html#modifying-request-data-before-building-entities
# Jul 12th 2021, 19:44 tyler.adam.lazenby I am
# Jul 12th 2021, 19:44 cnizzardini then try beforeMarshall
# Jul 12th 2021, 19:44 tyler.adam.lazenby That feels "stinky"
# Jul 12th 2021, 19:44 cnizzardini nothing wrong with doing it in the controller either
# Jul 12th 2021, 19:44 tyler.adam.lazenby hmmmmm
# Jul 12th 2021, 19:44 cnizzardini so beforeMarshall could be an option
# Jul 12th 2021, 19:43 tyler.adam.lazenby ```public function _setToken($token = null): string { if (!$token) { return Security::randomString(32); } return $token; }```
# Jul 12th 2021, 19:43 tyler.adam.lazenby Dang it, the entity doesn't save it by default