Properties

$qb

$qb : \Pixie\QueryBuilder\QueryBuilderHandler

QueryBuilder instance

Type

\Pixie\QueryBuilder\QueryBuilderHandler

$table

$table : string

Table name (without a prefix if there is one)

Type

string

$id

$id : string

name of the primary key column

Type

string

$allowedJoins

$allowedJoins : array

Allowed joinable columns

These can be one-to-many or many-to-many

Type

array

$searchable

$searchable : array

Allowed searchable columns

Type

array

$aliases

$aliases : array

Aliases to convert from client data format to server format

Aliases should be an array with the keys representing the client side format and the values representing the server side.

E.G. Client property = 'id' Server property = 'userID'

 $aliases = array('id'=>'userID')

Type

array

$required

$required : array

Array or required columns (used for inserts and updates)

Type

array

$fields

$fields : array

Static array of fields Can either be set statically or can be generated by the available instance variables

Type

array

$filters

$filters : array

Static array of filters

Type

array

$modelLinks

$modelLinks : array

Links to other model data

Type

array

Methods

__construct()

__construct() 

Constructs the class. Also converts GROUP_CONCAT fields to arrays

get()

get(string  $key) : mixed

Gets a value

Parameters

string $key

Model property to get

Returns

mixed —

Value of model property

set()

set(string  $key, mixed  $value) 

Sets a value

Parameters

string $key

Model property to set

mixed $value

Value to set

toJson()

toJson() : array

Provides an easy way to return the aliased data all at once

Returns

array

setQueryBuilder()

setQueryBuilder(\Pixie\QueryBuilder\QueryBuilderHandler  $qb) 

Sets the query builder instance

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

forge()

forge(array  $initialValues = array()) : \Pixie\QueryBuilder\QueryBuilderHandler

Initiates the model. Sets the "fields" variable if it exists

Parameters

array $initialValues

optional array of inital values to add to the query

Returns

\Pixie\QueryBuilder\QueryBuilderHandler —

QueryBuilder instance associated with the object

findOne()

findOne(array  $searchValues, array  $includes = array(), array  $fields = array(), boolean  $runFilters = true) : \FW\Data\Standard\Model

Find one model record

Parameters

array $searchValues

Values to search by (associative array) Prefix the key with ! for not equals check NOTE: if one of the values in the key-value pair is an array, it will be treated as an 'IN' check instead of an '=' check

array $includes

Joinable relationships to include

array $fields

List of fields to return

boolean $runFilters

If false, skip running filters. Used internally by add, edit, and editMany to prevent the returns from being caught For example, if we edit based on a filter, the returns may no longer match the filter

Returns

\FW\Data\Standard\Model

Values from the database as a Model object

findAll()

findAll(array  $searchValues, array  $includes = array(), array  $fields = array(), boolean  $runFilters = true) : array

Find all the model records

Parameters

array $searchValues

Values to search by (associative array) Prefix the key with ! for not equals check NOTE: if one of the values in the key-value pair is an array, it will be treated as an 'IN' check instead of an '=' check

array $includes

Joinable relationships to include

array $fields

List of fields to return

boolean $runFilters

If false, skip running filters. Used internally by add, edit, and editMany to prevent the returns from being caught For example, if we edit based on a filter, the returns may no longer match the filter

Returns

array —

Array of model classes

count()

count(array  $searchValues) : integer

Gets a count of record models for the specified search. Useful for pagination

Parameters

array $searchValues

Values to search by (associative array) Prefix the key with ! for not equals check NOTE: if one of the values in the key-value pair is an array, it will be treated as an 'IN' check instead of an '=' check

Returns

integer —

Number of results

findById()

findById(mixed  $id, array  $includes = array(), array  $fields = array()) : mixed|null

Convenience method used to find a singe record via the record's primary key

Parameters

mixed $id

Value in the primary key column to check

array $includes

Relationships to include

array $fields

Returns

mixed|null —

model record, or null if not found

add()

add(array  $values, array  $includes = array()) : \FW\Data\Standard\Model

Adds a new record to the database

Parameters

array $values

Values to add

array $includes

Includes to include

Returns

\FW\Data\Standard\Model

The newly added model class

updateMany()

updateMany(array  $valuesArray, array  $includes = array()) : array

Saves many models in one large database request. Handles editing or adding automatically.

Note it does not handle editing setting a value to null for technical reasons, so if values may change to and from null a different method should be used

Parameters

array $valuesArray

Array of model JSON. Same format as edit or add, but one per model changing

array $includes

Any relationships to include in the output. Note that relationships cannot be saved using this

Returns

array —

Array of models that were added or edited

edit()

edit(string|integer  $id, array  $values, array  $includes = array()) : \FW\Data\Standard\Model

Edits an existing database record

Parameters

string|integer $id

Primary Key of model record

array $values

Values to update

array $includes

Joins to include in select

Returns

\FW\Data\Standard\Model

Updated Model object

editMany()

editMany(array  $searchValues, array  $values, array  $includes = array(), array  $fields = array()) : array

Find all the model records

Parameters

array $searchValues

Values to search by (associative array) Prefix the key with ! for not equals check NOTE: if one of the values in the key-value pair is an array, it will be treated as an 'IN' check instead of an '=' check

array $values

Values to update

array $includes

Joinable relationships to include

array $fields

Returns

array —

Array of model classes

delete()

delete(string|integer  $id) 

Deletes an existing model record

Parameters

string|integer $id

Primary Key value

deleteMany()

deleteMany(array  $searchValues,   $includes = array(), array  $fields = array()) 

Deletes multiple model records based on a search filter

Parameters

array $searchValues

Values to search by (associative array) Prefix the key with ! for not equals check NOTE: if one of the values in the key-value pair is an array, it will be treated as an 'IN' check instead of an '=' check

$includes
array $fields

addFilter()

addFilter(\Closure  $fn) 

Adds a filter to the list of filters

Parameters

\Closure $fn

Filter callback

clearFilters()

clearFilters() 

Clears all applied filters

alias()

alias(array  $data, boolean  $flip = false) : array

Applies the values of self::$alias to an array

Parameters

array $data

Array to alias

boolean $flip

Whether or not to flip the alias (used for sending data back to the client)

Returns

array —

The aliased array

joinMany()

joinMany(\Pixie\QueryBuilder\QueryBuilderHandler  $qb, string  $name, string  $table, string  $key, boolean  $isToMany = true, \Closure  $joinOn = null, string  $id = null) 

Concise way of joining another table based on id comparison

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

QueryBuilder instance

string $name

name of generated column of ids

string $table

table name (without prefix if one exists)

string $key

id column name of table to compare

boolean $isToMany

if the relationship is one-to-many, this will be set to false

\Closure $joinOn

if there are extra join rules use them

string $id

id column name of the current table in the join

insertMany()

insertMany(\Pixie\QueryBuilder\QueryBuilderHandler  $qb, string  $table, string  $key, string|integer  $id, array  $values) 

Handles the insert/update side of the relationship based on id comparison

Used in many-to-many relationships

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

QueryBuilder Instance

string $table

Table name (without prefix)

string $key

id column name of $table

string|integer $id

ID of current row

array $values

Array of values to be placed in the join table

prefixForeignKey()

prefixForeignKey(string|array  $values, string  $prefix = 'FK_') : string|array

Prefixes $values with a predefined foreign key prefix

Parameters

string|array $values

String or array of strings to prefix

string $prefix

string to prefix with

Returns

string|array —

String or array of prefixed values

findProcess()

findProcess(\Pixie\QueryBuilder\QueryBuilderHandler  $qb, array  $searchValues, array  $includes, array  $fields) 

Helper used by findOne and findAll to handle some of the join and search legwork

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

QueryBuilder instance

array $searchValues

Values to search by

array $includes

Relationships to include

array $fields

Array of fields to return

searchProcess()

searchProcess(\Pixie\QueryBuilder\QueryBuilderHandler  $qb, array  $searchValues) 

Helper used by findProcess, deleteMany, and editMany to process search keys

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

QueryBuilder instance

array $searchValues

Values to search by

buildOnDuplicateData()

buildOnDuplicateData(array  $fields = null) : array

Builds the array for onDuplicateKeyUpdate Used internally in updateMany

Parameters

array $fields

Fields for keys to update. Does not support aliases

Returns

array —

Associative array used for Pixie to make the request

addLink()

addLink(string  $name, \Closure  $fn) 

Adds a link to the list of model links

Parameters

string $name

name of the property

\Closure $fn

Function to call for the link

runFilters()

runFilters(\Pixie\QueryBuilder\QueryBuilderHandler  $qb) 

Filters things

Parameters

\Pixie\QueryBuilder\QueryBuilderHandler $qb

QueryBuilder instance

hasRequired()

hasRequired(array  $values) : boolean

Ensures that the passed in values supply all the required values

Parameters

array $values

Values to check

Returns

boolean —

Whether or not $values contains all needed properties

initFields()

initFields() 

Initialize the fields (pull them from class properties)