This repository was archived by the owner on Jul 16, 2023. It is now read-only.
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
[RFC] Improve compatibility with original Eloquent methods #84
Open
Description
There are some changes in Ardent that made some methods incompatible or behaving differently than their original counterparts. Here are some examples that should be fixed in a new major version to make Ardent easier for newcomers:
save
receives custom rules and messages, plus custom hooks, besides the original options, but in a different order. This makes Eloquent code non-portable into Ardent.- Although
update
operations are used in a similar manner by the end-user, this is the original Eloquent method. I'm not sure if it calls Ardent Validations, but I think it should work similarly assave
does. - Setting fields in different ways yield different behaviors:
- setting fields directly in the
$attributes
param does not call mutators. Is this expected? Is this a bug in Eloquent? - setting a new field with
$this->field = 'bla'
inside a mutator does not validate it, but using$this->attributes['field'] = 'bla'
apparently does. - setting a field as a new property in an object does not validate it upon
update
call ($user->data = 'bla'; $user->update();
)
- setting fields directly in the
- there is
updateUniques
, that have the same signature assave
but a different name pattern (it is prefixed). This also creates confusion since a user would expectupdate
andsave
to call validations, butupdate
don't andupdateUniques
looks related only tounique
rules, what's not only the case. - validation rules should be automatically fixed for
update
calls, removing validation for uniques. This is currently done inside theupdateUniques
method, by an auxiliary method.
Suggestions:
save
andupdate
should follow Eloquent's signatures and always call validation on the final data before writing to the database. This should be accomplished using a decent test structure (Test Coverage #55), so we make sure no use case is forgotten.validate
should verify if it's a new or existent entry (save/update call) and fix validation for uniques accordingly and transparently- creation of other methods to handle custom options:
customSave
andcustomUpdate
, that could have the same signature of custom rules, messages and hooks, ORsetCustomValidation
that would set rules and messages for the nextvalidate
call, andsetCustomSaveHooks
that would do the same for the hooks. This is also related to What's the usage of before and afterSave as arguments in save method? #74 since those hooks have a similar usage of plain code before and after the method calls.