Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for private columns and filtered objects #124

Open
wants to merge 3 commits into
base: 3.3/develop
Choose a base branch
from

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