Skip to content

Conversation

@svenbw
Copy link

@svenbw svenbw commented Jan 5, 2016

When one wants to send an ORM object trough an API some columns should be remain private or hidden. This can be done using the $_private variable in the model.
Calls like as_array() will return only the non private column values.

An extra function as_object() is also added this will return a new object instance with the column values, it differs with the casted array ((object)$some_model->as_array()) that each value will be returned as it's native type (string, int or float).

If the functions are called with the TRUE argument (as_array(TRUE) or as_object(TRUE)) all column values will be returned.
Also leaving $_private empty will return all column values which assures backwards compatibility.

@enov
Copy link
Contributor

enov commented Jan 8, 2016

@svenbw thank you for your pull request, it's very comprehensive.

Unfortunately, most of the active maintainers are probably not using this module. That's why PRs are sitting around here for a while until someone merges them. Sorry :(

@svenbw
Copy link
Author

svenbw commented Jan 8, 2016

@enov in the openclassifieds2 project the ORM module is still used by @neo22s, so maybe there is still some hope :-)

@svenbw
Copy link
Author

svenbw commented Apr 5, 2016

Added behaviors for ORM.
This commit adds behaviors to the ORM model; it is inspired by the behaviors in Laravel and allow a model to write/modify data during the creation, updating or creation of the model.
A good example is a slug for a page, this is based on a title and needs to be updated during the commit.
It is possible to update data in a model creating a subclass of the model (e.g. ORM_Slugged) but if there is the need to update another column one needs to create another subclass.

With behaviors one can add a slug, guid, creation timestamp, ... by defining the behavior() function in the model. This function returns an array just like rules and filters.
I've included a guid and slug behavior in the default ORM module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants