You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 21, 2026. It is now read-only.
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.
@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 :(
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
$_privatevariable 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,intorfloat).If the functions are called with the TRUE argument (
as_array(TRUE)oras_object(TRUE)) all column values will be returned.Also leaving
$_privateempty will return all column values which assures backwards compatibility.