Download the PHP package neat/object without Composer
On this page you can find all versions of the php package neat/object. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package object
Neat Object components
Neat object component adds a simple yet intuitive ORM layer on top of the Neat database component.
Getting started
To install this package, simply issue composer on the command line:
Then initialize the object manager:
Creating an entity
Entities can be just plain old PHP objects
To persist these entities into the database, we can use a repository:
Find by identifier
If you know the identifier for your entity, you can access it using the
has
and get
methods.
To find and entity from a table using a composed primary key, you should pass the identifiers as an array.
Find using a query
The repository allows you to query for entities in many ways:
one
returns one entity (or null if none matched the query)all
returns all entities matched by the query as an arraycollection
returns a collection instance containing the matched entitiesiterate
returns a generator allowing you to iterate over the matched entitiesselect
returns a mutable query builder that allows chaining any of the methods abovesql
returns a query object using a handwritten SQL query supplied as string
Each of these methods can be passed a query in several ways:
Find using static access
To prevent littering your code with manager and repository instances, you can
use the Storage
trait to allow for static repository access:
Relations
If you need relations just use the Relations
trait which supplies factory functions
for hasOne/-Many and belongsToOne/-Many relations.
When you have multiple relations to the same class, make sure you assign each of them a unique role using the second parameter to avoid collisions between them:
References
The column names and table names used for each relation have defaults that
are determined by the Policy
. When these defaults don't work, you can
override them by passing a configuration closure as third parameter to the
relation method of you choice:
Accessors
Accessor methods allow you to call methods like , , , , , and on your entity object directly:
Translating to is done by the Policy. In its constructor you can provide a pluralize function to allow for proper translations:
Collections
Collections wrap an array of multiple items and offer a chainable way of
accessing these items using several operations. Relations to multiple
instances of a class (hasMany and belongsToMany) offer the same
Collectible
API: