Download the PHP package granadaorm/granada without Composer
On this page you can find all versions of the php package granadaorm/granada. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download granadaorm/granada
More information about granadaorm/granada
Files in granadaorm/granada
Package granada
Short Description Active Record / ORM with eager loading, lazy loading and more
License BSD-2-Clause BSD-3-Clause BSD-4-Clause
Homepage https://github.com/GranadaORM/Granada
Informations about the package granada
Granada
Granada is a easy to use Active Record implementation, and ORM based on Idiorm/Paris.
A quick view
You can read the Paris Docs on paris.readthedocs.org but be sure to read the additions below.
Install
Using composer:
Configure it:
As always, you can check it in detail on Paris documentation
Additions
Eager loading
You can use the "with" method to add relationships eager loading to the query.
will use 3 querys to fetch the users and the relationships:
It is possible to get the relationships results for each result, this way
Lazy loading
Triying to access to a not fetched relationship will call and return it
Notice that if there is no result for avatar
on the above example it will throw a Notice: Trying to get property of non-object...
Note: Maybe worth the effort to create a NULL object for this use case and others.
Chained relationships with arguments for eager loading
It is possible to chain relationships and add arguments to the relationships calls
Custom query filters
It's possible to create static functions on the model to work as filter in queries. Prepended it with "filter_":
and call it on a static call
Multiple additions names for Granada
- select_raw
- group_by_raw
- order_by_raw
- raw_join
- insert : To create and save multiple elements from an array
- pluck : returns a single column from the result.
- find_pairs : Return array of key=>value as result
- save : accepts a boolean to use "ON DUPLICATE KEY UPDATE" (just for Mysql)
- delete_many (accept join clauses)
Overload SET
Overload GET and MISSING property
Of course, you still can define functions with the property name if you want to overload it completely.
Define resultSet (collection type) class on Model
Now is possible to define the resultSet class returned for a model instances result. (if return_result_sets
config variable is set to true)
Notice that the resultSet class defined must extends Granada\ResultSet
and must be loaded
ResultSets are defined by the model in the result, as you can see above.
On eager load, the results are consistent.
For example, if we have a Content
model, with $resultSetClass = 'TreeResultSet'
and a has_many
relationship defined as media
:
will return a TreeResultSet
with instances of Content
each with a property $media
containing Granada\ResultSet
(the default resultSet if none if defined on the Model)
Basic Documentation comes from Paris
Paris
Feature complete
Paris is now considered to be feature complete as of version 1.4.0. Whilst it will continue to be maintained with bug fixes there will be no further new features added.
A lightweight Active Record implementation for PHP5.
Built on top of Idiorm.
Tested on PHP 5.2.0+ - may work on earlier versions with PDO and the correct database drivers.
Released under a BSD license.
Features
- Extremely simple configuration.
- Exposes the full power of Idiorm's fluent query API.
- Supports associations.
- Simple mechanism to encapsulate common queries in filter methods.
- Built on top of PDO.
- Uses prepared statements throughout to protect against SQL injection attacks.
- Database agnostic. Currently supports SQLite, MySQL, Firebird and PostgreSQL. May support others, please give it a try!
- Supports collections of models with method chaining to filter or apply actions to multiple results at once.
- Multiple connections are supported
History
Granada was originally developed by Erik Wiesenthal, up to version 1.5. Further development started by Josh Marshall to release version 2.0