Manipulate zuora objects and their relationships without writing a single line of ZOQL.
Pull request Compare This branch is 5 commits ahead, 11 commits behind OlivierBarbier:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Zuora ORM

StyleCI Build Status Latest Stable Version Total Downloads Latest Unstable Version License


The Zuora ORM provides a simple way for working with Zuora objects without writing ZOQL queries. Each zuora object has a corresponding "Model" which is used to interact with that object.

Basic Usage

Retrieving All Models

$accounts = Account::all();

Retrieving A Record By Primary Key

$account = account::find(1);


Querying Using Zuora ORM Models

$accounts = Account::where('Status', '=', 'Active')->get();

foreach ($accounts as $account)

Zuora ORM Aggregates

Of course, you may also use the query builder aggregate functions.

$count = Account::where('Status', '=', 100)->get()->count();

Insert, Update, Delete

Using The Model Create Method

// Create a new user in the database...
$account = Account::create(array('name' => 'my test account'));

Updating A Retrieved Model

To update a model, you may retrieve it, change an attribute, and use the save method:

$account = Account::find(1);

$account->status = 'Active';


Deleting An Existing Model

To delete a model, simply call the delete method on the instance:

$account = Account::find(1);



One To One

Retrieve A One To One Relation

For example, a Subscription model have one Account.

We may retrieve it using Zuora ORM's dynamic properties:

$account = Subscription::find(1)->account;

The SQL performed by this statement will be as follows:

select * from Subscription where Id = 1

select * from Account where Id = $subscription->Id

One To Many

An example of a one-to-many relation is an account that "has many" subscriptions.

We can access the account's subscriptionss through the dynamic property:

$subscriptions = Account::find(1)->subscriptions;

If you need to add further constraints to which subscriptions are retrieved, you may call the subscriptions method and continue chaining conditions:

$subscriptions = Account::find(1)->subscriptions()->where('Status', '=', 'Active')->get()->first();

Querying Relations

Querying Relations When Selecting

When accessing the records for a model, you may wish to limit your results based on the existence of a relationship. For example, you wish to pull all accounts that have at least one subscription:

$accounts = Account::all()->filter(function($account) { return $account->subscription()->count() > 0; });

Dynamic Properties

Zuora ORM allows you to access your relations via dynamic properties. Zuora ORM will automatically load the relationship for you, and is even smart enough to know whether to call the get (for one-to-many relationships) or first (for one-to-one relationships) method. It will then be accessible via a dynamic property by the same name as the relation.

$subscription = Subscription::find(1);

Instead of echoing the user's email like this:

echo $subscription->account()->get()->first()->Name;

It may be shortened to simply:

echo $subscription->account->Name;

Note: Relationships that return many results will return an instance of the Illuminate\Support\Collection class.


All multi-result sets returned by Zuora ORM, either via the get method or a relationship, will return a collection object. This object implements the IteratorAggregate PHP interface so it can be iterated over like an array. However, this object also has a variety of other helpful methods for working with result sets.

Iterating Collections

Zuora ORM collections also contain a few helpful methods for looping and filtering the items they contain:

Filtering Collections

When filtering collections, the callback provided will be used as callback for array_filter.

$accounts = $accounts->filter(function($account)
    return $account->hasSubcriptions();

Applying A Callback To Each Collection Object

$subscriptions = Account::find(1)->subscriptions;


Sorting A Collection By A Value

$subscriptions = $subscriptions->sortBy(function($subscription)
    return $subscription->CreatedDate;