Closed BenRutlandWeb closed 3 years ago
The meta property returns an instance of Meta
which currently has no knowledge of the object type calling the HasMeta
trait.
Passing the object type to the Meta
constructor would allow for the Meta
object to have the save
, update
methods.
delete
works quite differently from the Model
s version, in that the property is passed instead of deleting the whole "model". I think this should work more like the getters/setters, as it's unlikely that one would want to delete all meta.
The Meta
class would also need to handle clean/dirty values so as to not update every property on save
. ANother thing to consider is the meta caching strategy. Currently, the getter stores the entire object meta as a property instead of querying the db on every call.
The Meta
class also needs to know the Model
relationship. Perhaps it's better to pass the Model
to the Meta
class in order to perform the actions related to the model.
Instead of using an "accessor" for meta, the meta should be accessed via a method invocation. This is consistent with laravel's relationships - the return is an instance of Meta
instead of a Builder
.
There isn't a simple way to use WordPress APIs to bulk update/delete attributes. These will need to be iterated over to update/delete. The getDirty
method is useful here to only update the desired properties.
Another point to make is: unsetting attributes don't change the Meta class' clean/dirty state. Upon save
, the meta values are updated, but not deleted. Meta will have to be manually and obviously deleted with the provided method rather than relying on the model's state to stay in sync with the db.
Is your feature request related to a problem? Please describe. The
HasMeta
trait allows for the object meta to be fetched. Nice enough. But it would be cool if you could update/delete the meta data too.Describe the solution you'd like A method or getter/setter to update and delete the meta data attached to the particular post. E.g.
Describe alternatives you've considered Using
update_metadata
anddelete_metadata
Additional context The
Meta
model already exists, additional methods would need to be added to useupdate_metadata
anddelete_metadata
under the hood.