Skip to content
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
@igorsantos07

Description

@igorsantos07

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 as save 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();)
  • there is updateUniques, that have the same signature as save but a different name pattern (it is prefixed). This also creates confusion since a user would expect update and save to call validations, but update don't and updateUniques looks related only to unique 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 the updateUniques method, by an auxiliary method.

Suggestions:

  • save and update 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:
    1. customSave and customUpdate, that could have the same signature of custom rules, messages and hooks, OR
    2. setCustomValidation that would set rules and messages for the next validate call, and setCustomSaveHooks 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions