{"id":21467408,"url":"https://github.com/elusivecodes/fyreorm","last_synced_at":"2025-07-15T05:31:22.407Z","repository":{"id":62508461,"uuid":"469328759","full_name":"elusivecodes/FyreORM","owner":"elusivecodes","description":"FyreORM is a free, open-source database ORM library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-15T10:40:46.000Z","size":657,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-15T11:31:15.478Z","etag":null,"topics":["database","mysql","orm","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-13T09:46:55.000Z","updated_at":"2024-11-15T10:40:30.000Z","dependencies_parsed_at":"2023-12-23T08:36:10.969Z","dependency_job_id":"338f3452-8380-4353-946d-9345a5079121","html_url":"https://github.com/elusivecodes/FyreORM","commit_stats":null,"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreORM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreORM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreORM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreORM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreORM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017470,"owners_count":17560518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","mysql","orm","php"],"created_at":"2024-11-23T08:17:54.097Z","updated_at":"2025-07-15T05:31:22.393Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreORM\r\n\r\n**FyreORM** is a free, open-source database ORM for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Models](#models)\r\n    - [Schema](#schema)\r\n    - [Entities](#entities)\r\n    - [Query Methods](#query-methods)\r\n    - [Relationship Methods](#relationship-methods)\r\n    - [Behavior Methods](#behavior-methods)\r\n    - [Validation](#validation)\r\n    - [Callbacks](#callbacks)\r\n- [Queries](#queries)\r\n    - [Delete](#delete)\r\n    - [Insert](#insert)\r\n    - [Replace](#replace)\r\n    - [Select](#select)\r\n    - [Update](#update)\r\n    - [Update Batch](#update-batch)\r\n- [Results](#results)\r\n- [Relationships](#relationships)\r\n    - [Belongs To](#belongs-to)\r\n    - [Has Many](#has-many)\r\n    - [Has One](#has-one)\r\n    - [Many To Many](#many-to-many)\r\n- [Behavior Registry](#behavior-registry)\r\n- [Behaviors](#behaviors)\r\n    - [Timestamp](#timestamp)\r\n- [Rules](#rules)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/orm\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\ORM\\ModelRegistry;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$modelRegistry = new ModelRegistry($container);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *ModelRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(ModelRegistry::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$modelRegistry = $container-\u003euse(ModelRegistry::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Add Namespace**\r\n\r\nAdd a namespace for loading models.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$modelRegistry-\u003eaddNamespace($namespace);\r\n```\r\n\r\n**Build**\r\n\r\nBuild a [*Model*](#models).\r\n\r\n- `$classAlias` is a string representing the model class alias.\r\n\r\n```php\r\n$model = $modelRegistry-\u003ebuild($classAlias);\r\n```\r\n\r\n[*Model*](#models) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n**Clear**\r\n\r\nClear all namespaces and models.\r\n\r\n```php\r\n$modelRegistry-\u003eclear();\r\n```\r\n\r\n**Create Default Model**\r\n\r\nCreate a default [*Model*](#models).\r\n\r\n```php\r\n$model = $modelRegistry-\u003ecreateDefaultModel();\r\n```\r\n\r\n[*Model*](#models) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n**Get Default Model Class**\r\n\r\nGet the default model class name.\r\n\r\n```php\r\n$defaultModelClass = $modelRegistry-\u003egetDefaultModelClass();\r\n```\r\n\r\n**Get Namespaces**\r\n\r\nGet the namespaces.\r\n\r\n```php\r\n$namespaces = $modelRegistry-\u003egetNamespaces();\r\n```\r\n\r\n**Has Namespace**\r\n\r\nDetermine whether a namespace exists.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$hasNamespace = $modelRegistry-\u003ehasNamespace($namespace);\r\n```\r\n\r\n**Is Loaded**\r\n\r\nDetermine whether a model is loaded.\r\n\r\n- `$alias` is a string representing the model alias.\r\n\r\n```php\r\n$isLoaded = $modelRegistry-\u003eisLoaded($alias);\r\n```\r\n\r\n**Remove Namespace**\r\n\r\nRemove a namespace.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$modelRegistry-\u003eremoveNamespace($namespace);\r\n```\r\n\r\n**Set Default Model Class**\r\n\r\nSet the default model class name.\r\n\r\n- `$defaultModelClass` is a string representing the default model class name.\r\n\r\n```php\r\n$modelRegistry-\u003esetDefaultModelClass($defaultModelClass);\r\n```\r\n\r\n**Unload**\r\n\r\nUnload a model.\r\n\r\n- `$alias` is a string representing the model alias.\r\n\r\n```php\r\n$modelRegistry-\u003eunload($alias);\r\n```\r\n\r\n**Use**\r\n\r\nLoad a shared [*Model*](#models) instance.\r\n\r\n- `$alias` is a string representing the model alias.\r\n- `$classAlias` is a string representing the model class alias, and will default to the model alias.\r\n\r\n```php\r\n$model = $modelRegistry-\u003euse($alias, $classAlias);\r\n```\r\n\r\n[*Model*](#models) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n\r\n## Models\r\n\r\nCustom models can be created by extending the `\\Fyre\\ORM\\Model` class, suffixing the class name with \"*Model*\".\r\n\r\nTo allow autoloading an instance of your model, add the the namespace to the *ModelRegistry*.\r\n\r\n**Delete Query**\r\n\r\nCreate a new [*DeleteQuery*](#delete).\r\n\r\n- `$options` is an array containing options for the query.\r\n    - `alias` is a string representing the table alias, and will default to the model alias.\r\n\r\n```php\r\n$query = $model-\u003edeleteQuery($options);\r\n```\r\n\r\n**Get Connection**\r\n\r\nGet the [*Connection*](https://github.com/elusivecodes/FyreDB#connections).\r\n\r\n- `$type` is a string representing the connection type, and will default to `self::WRITE`.\r\n\r\n```php\r\n$connection = $model-\u003egetConnection($type);\r\n```\r\n\r\nModels use [*ConnectionManager*](https://github.com/elusivecodes/FyreDB) for database connections, and you can specify the connection to use by setting the `connectionKeys` property of your models, or using the `setConnection` method.\r\n\r\n```php\r\nprotected array $connectionKeys = [\r\n    self::WRITE =\u003e 'default',\r\n    self::READ =\u003e 'read_replica'\r\n];\r\n```\r\n\r\nIf the `self::READ` key is omitted, it will fallback to the `self::WRITE` connection for database reads.\r\n\r\n**Insert Query**\r\n\r\nCreate a new [*InsertQuery*](#insert).\r\n\r\n```php\r\n$query = $model-\u003einsertQuery();\r\n```\r\n\r\n**Replace Query**\r\n\r\nCreate a new [*ReplaceQuery*](#replace).\r\n\r\n```php\r\n$query = $model-\u003ereplaceQuery();\r\n```\r\n\r\n**Select Query**\r\n\r\nCreate a new [*SelectQuery*](#select).\r\n\r\n- `$options` is an array containing options for the query.\r\n    - `alias` is a string representing the table alias, and will default to the model alias.\r\n    - `connectionType` is a string representing the connection type, and will default to `self::READ`.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n\r\n```php\r\n$query = $model-\u003eselectQuery($options);\r\n```\r\n\r\n**Set Connection**\r\n\r\nSet the [*Connection*](https://github.com/elusivecodes/FyreDB#connections).\r\n\r\n- `$connection` is a [*Connection*](https://github.com/elusivecodes/FyreDB#connections).\r\n- `$type` is a string representing the connection type, and will default to `self::WRITE`.\r\n\r\n```php\r\n$model-\u003esetConnection($connection, $type);\r\n```\r\n\r\n**Subquery**\r\n\r\nCreate a new subquery [*SelectQuery*](#select).\r\n\r\n- `$options` is an array containing options for the query.\r\n    - `alias` is a string representing the table alias, and will default to the model alias.\r\n    - `connectionType` is a string representing the connection type, and will default to `self::READ`.\r\n\r\n```php\r\n$query = $model-\u003esubquery($options);\r\n```\r\n\r\n**Update Query**\r\n\r\nCreate a new [*UpdateQuery*](#update).\r\n\r\n- `$options` is an array containing options for the query.\r\n    - `alias` is a string representing the table alias, and will default to the model alias.\r\n\r\n```php\r\n$query = $model-\u003eupdateQuery($options);\r\n```\r\n\r\n**Update Batch Query**\r\n\r\nCreate a new [*UpdateBatchQuery*](#update-batch).\r\n\r\n- `$options` is an array containing options for the query.\r\n    - `alias` is a string representing the table alias, and will default to the model alias.\r\n\r\n```php\r\n$query = $model-\u003eupdateBatchQuery($options);\r\n```\r\n\r\n\r\n### Schema\r\n\r\n**Alias Field**\r\n\r\nAlias a field name.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$alias` is a string representing the alias, and will default to the model alias.\r\n\r\n```php\r\n$aliasField = $model-\u003ealiasField($field, $alias);\r\n```\r\n\r\n**Get Alias**\r\n\r\nGet the model alias.\r\n\r\n```php\r\n$alias = $model-\u003egetAlias();\r\n```\r\n\r\nBy default, the alias will be the class alias.\r\n\r\n**Get Auto Increment Key**\r\n\r\nGet the table auto increment column.\r\n\r\n```php\r\n$autoIncrementKey = $model-\u003egetAutoIncrementKey();\r\n```\r\n\r\n**Get Class Alias**\r\n\r\nGet the model class alias.\r\n\r\n```php\r\n$classAlias = $model-\u003egetClassAlias();\r\n```\r\n\r\nBy default, the alias will be the class name or the alias used when loading the model with *ModelRegistry*.\r\n\r\n**Get Display Name**\r\n\r\nGet the display name.\r\n\r\n```php\r\n$displayName = $model-\u003egetDisplayName();\r\n```\r\n\r\nBy default, the display name will be the first column in the schema with the name of either *\"name\"*, *\"title\"* or *\"label\"*, or you can specify a column using the `displayName` property in your models.\r\n\r\n```php\r\nprotected string $displayName = 'display_name';\r\n```\r\n\r\n**Get Primary Key**\r\n\r\nGet the primary key(s).\r\n\r\n```php\r\n$primaryKeys = $model-\u003egetPrimaryKey();\r\n```\r\n\r\n**Get Route Key**\r\n\r\nGet the route key.\r\n\r\n```php\r\n$routeKey = $model-\u003egetRouteKey();\r\n```\r\n\r\n**Get Schema**\r\n\r\nGet the [*TableSchema*](https://github.com/elusivecodes/FyreSchema#table-schemas).\r\n\r\n```php\r\n$tableSchema = $model-\u003egetSchema();\r\n```\r\n\r\n**Get Table**\r\n\r\nGet the table name.\r\n\r\n```php\r\n$table = $model-\u003egetTable();\r\n```\r\n\r\nBy default, the table name will be the snake case form of the model class alias, or you can specify a table name using the `table` property in your models.\r\n\r\n```php\r\nprotected string $table = 'my_table';\r\n```\r\n\r\n**Set Alias**\r\n\r\nSet the model alias.\r\n\r\n- `$alias` is a string representing the model alias.\r\n\r\n```php\r\n$model-\u003esetAlias($alias);\r\n```\r\n\r\n**Set Class Alias**\r\n\r\nSet the model class alias.\r\n\r\n- `$classAlias` is a string representing the model class alias.\r\n\r\n```php\r\n$model-\u003esetClassAlias($classAlias);\r\n```\r\n\r\n**Set Display Name**\r\n\r\nSet the display name.\r\n\r\n- `$displayName` is a string representing the display name.\r\n\r\n```php\r\n$model-\u003esetDisplayName($displayName);\r\n```\r\n\r\n**Set Table**\r\n\r\nSet the table name.\r\n\r\n- `$table` is a string representing the table name.\r\n\r\n```php\r\n$model-\u003esetTable($table);\r\n```\r\n\r\n\r\n### Entities\r\n\r\nModels will use the [*EntityLocator*](https://github.com/elusivecodes/FyreEntity#entity-locator) to find an entity class using the model class alias.\r\n\r\nYou can map a model alias to a specific entity class using the [*EntityLocator*](https://github.com/elusivecodes/FyreEntity#entity-locator).\r\n\r\n```php\r\n$entityLocator-\u003emap($alias, $className);\r\n```\r\n\r\n**Load Into**\r\n\r\nLoad contained data into entity.\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n- `$contain` is an array containing the relationships to contain.\r\n\r\n```php\r\n$model-\u003eloadInto($entity, $contain);\r\n```\r\n\r\n**New Empty Entity**\r\n\r\nBuild a new empty [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n```php\r\n$entity = $model-\u003enewEmptyEntity();\r\n```\r\n\r\n**New Entity**\r\n\r\nBuild a new [*Entity*](https://github.com/elusivecodes/FyreEntity) using data.\r\n\r\n- `$data` is an array containing the data.\r\n- `$options` is an array containing entity options.\r\n    - `associated` is an array containing the relationships to parse, and will default to *null*.\r\n    - `accessible` is an array containing accessible fields, and will default to *null*.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n    - `parse` is a boolean indicating whether to parse user data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `validate` is a boolean indicating whether to validate user data, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity, and will default to *false*.\r\n    - `new` is a boolean indicating whether to mark the entity as new, and will default to *null*.\r\n\r\n```php\r\n$entity = $model-\u003enewEntity($data, $options);\r\n```\r\n\r\n**New Entities**\r\n\r\nBuild multiple new entities using user data.\r\n\r\n- `$data` is an array containing the data.\r\n- `$options` is an array containing entity options.\r\n    - `associated` is an array containing the relationships to parse, and will default to *null*.\r\n    - `accessible` is an array containing accessible fields, and will default to *null*.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n    - `parse` is a boolean indicating whether to parse user data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `validate` is a boolean indicating whether to validate user data, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity, and will default to *false*.\r\n    - `new` is a boolean indicating whether to mark the entity as new, and will default to *null*.\r\n\r\n```php\r\n$entities = $model-\u003enewEntities($data, $options);\r\n```\r\n\r\n**Patch Entity**\r\n\r\nUpdate an Entity using user data.\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n- `$data` is an array containing the data.\r\n- `$options` is an array containing entity options.\r\n    - `associated` is an array containing the relationships to parse, and will default to *null*.\r\n    - `accessible` is an array containing accessible fields, and will default to *null*.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n    - `parse` is a boolean indicating whether to parse user data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `validate` is a boolean indicating whether to validate user data, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity, and will default to *false*.\r\n    - `new` is a boolean indicating whether to mark the entity as new, and will default to *null*.\r\n\r\n```php\r\n$model-\u003epatchEntity($entity, $data, $options);\r\n```\r\n\r\n**Patch Entities**\r\n\r\nUpdate multiple entities using user data.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$data` is an array containing the data.\r\n- `$options` is an array containing entity options.\r\n    - `associated` is an array containing the relationships to parse, and will default to *null*.\r\n    - `accessible` is an array containing accessible fields, and will default to *null*.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n    - `parse` is a boolean indicating whether to parse user data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `validate` is a boolean indicating whether to validate user data, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity, and will default to *false*.\r\n    - `new` is a boolean indicating whether to mark the entity as new, and will default to *null*.\r\n\r\n```php\r\n$model-\u003epatchEntities($entities, $data, $options);\r\n```\r\n\r\n\r\n### Query Methods\r\n\r\n**Delete**\r\n\r\nDelete an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n- `$options` is an array containing delete options.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `cascade` is a boolean indicating whether to cascade deletes, and will default to *true*.\r\n\r\n```php\r\n$result = $model-\u003edelete($entity, $options);\r\n```\r\n\r\n**Delete All**\r\n\r\nDelete all rows matching conditions.\r\n\r\n- `$conditions` is an array or string representing the where conditions.\r\n\r\n```php\r\n$affectedRows = $model-\u003edeleteAll($conditions);\r\n```\r\n\r\nThis method will not use callbacks or cascade to related data.\r\n\r\n**Delete Many**\r\n\r\nDelete multiple entities.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$options` is an array containing delete options.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `cascade` is a boolean indicating whether to cascade deletes, and will default to *true*.\r\n\r\n```php\r\n$result = $model-\u003edeleteMany($entities, $options);\r\n```\r\n\r\n**Exists**\r\n\r\nDetermine whether matching rows exist.\r\n\r\n- `$conditions` is an array or string representing the where conditions.\r\n\r\n```php\r\n$exists = $model-\u003eexists($conditions);\r\n```\r\n\r\n**Find**\r\n\r\nCreate a new [*SelectQuery*](#select).\r\n\r\n- `$data` is an array containing the query data.\r\n    - `connectionType` is a string representing the connection type, and will default to `self::READ`.\r\n    - `fields` is an array or string representing the fields to select.\r\n    - `contain` is a string or array containing the relationships to contain.\r\n    - `join` is an array containing the tables to join.\r\n    - `conditions` is an array or string representing the where conditions.\r\n    - `orderBy` is an array or string representing the fields to order by.\r\n    - `groupBy` is an array or string representing the fields to group by.\r\n    - `having` is an array or string representing the having conditions.\r\n    - `limit` is a number indicating the query limit.\r\n    - `offset` is a number indicating the query offset.\r\n    - `epilog` is a string representing the epilog for the query.\r\n    - `autoFields` is a boolean indicating whether to enable auto fields.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n\r\n```php\r\n$query = $model-\u003efind($data);\r\n```\r\n\r\n**Get**\r\n\r\nRetrieve a single entity.\r\n\r\n- `$primaryValues` is a string, integer or array containing the primary key value(s).\r\n- `$data` is an array containing the query data.\r\n    - `connectionType` is a string representing the connection type, and will default to `self::READ`.\r\n    - `fields` is an array or string representing the fields to select.\r\n    - `contain` is a string or array containing the relationships to contain.\r\n    - `join` is an array containing the tables to join.\r\n    - `epilog` is a string representing the epilog for the query.\r\n    - `autoFields` is a boolean indicating whether to enable auto fields.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n\r\n```php\r\n$entity = $model-\u003eget($primaryValues, $data);\r\n```\r\n\r\n**Resolve Route Binding**\r\n\r\nResolve an entity from a route.\r\n\r\n- `$value` is a string or integer containing the route key value.\r\n- `$field` is a string representing the route key.\r\n- `$parent` is an *Entity* representing the parent entity, and will default to *null*.\r\n\r\n```php\r\n$entity = $model-\u003eresolveRouteBinding($value, $field, $parent);\r\n```\r\n\r\n**Save**\r\n\r\nSave an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n- `$options` is an array containing save options.\r\n    - `checkExists` is a boolean indicating whether to check if new entities exist, and will default to *true*.\r\n    - `checkRules` is a boolean indicating whether to validate the [*RuleSet*](#rules), and will default to *true*.\r\n    - `saveRelated` is a boolean indicating whether to save related data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity after saving, and will default to *true*.\r\n\r\n```php\r\n$result = $model-\u003esave($entity, $options);\r\n```\r\n\r\n**Save Many**\r\n\r\nSave multiple entities.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$options` is an array containing save options.\r\n    - `checkExists` is a boolean indicating whether to check if new entities exist, and will default to *true*.\r\n    - `checkRules` is a boolean indicating whether to validate the [*RuleSet*](#rules), and will default to *true*.\r\n    - `saveRelated` is a boolean indicating whether to save related data, and will default to *true*.\r\n    - `events` is a boolean indicating whether to trigger model/behavior events, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity after saving, and will default to *true*.\r\n\r\n```php\r\n$result = $model-\u003esaveMany($entities, $options);\r\n```\r\n\r\n**Update All**\r\n\r\nUpdate all rows matching conditions.\r\n\r\n- `$data` is an array of values to update.\r\n- `$conditions` is an array or string representing the where conditions.\r\n\r\n```php\r\n$affectedRows = $model-\u003eupdateAll($data, $conditions);\r\n```\r\n\r\nThis method will not use callbacks.\r\n\r\n\r\n### Relationship Methods\r\n\r\n**Add Relationship**\r\n\r\nAdd a [*Relationship*](#relationships).\r\n\r\n- `$relationship` is a [*Relationship*](#relationships).\r\n\r\n```php\r\n$model-\u003eaddRelationship($relationship);\r\n```\r\n\r\n**Get Relationship**\r\n\r\nGet a [*Relationship*](#relationships).\r\n\r\n- `$name` is a string representing the relationship name.\r\n\r\n```php\r\n$relationship = $model-\u003egetRelationship($name);\r\n```\r\n\r\n**Get Relationships**\r\n\r\nGet all relationships.\r\n\r\n```php\r\n$relationships = $model-\u003egetRelationships();\r\n```\r\n\r\n**Has Relationship**\r\n\r\nDetermine whether a [*Relationship*](#relationships) exists.\r\n\r\n- `$name` is a string representing the relationship name.\r\n\r\n```php\r\n$hasRelationship = $model-\u003ehasRelationship($name);\r\n```\r\n\r\n**Remove Relationship**\r\n\r\nRemove an existing [*Relationship*](#relationships).\r\n\r\n- `$name` is a string representing the relationship name.\r\n\r\n```php\r\n$model-\u003eremoveRelationship($name);\r\n```\r\n\r\n\r\n### Behavior Methods\r\n\r\n**Add Behavior**\r\n\r\nAdd a [*Behavior*](#behaviors) to the *Model*.\r\n\r\n- `$name` is a string representing the behavior name.\r\n- `$options` is an array containing behavior options.\r\n\r\n```php\r\n$model-\u003eaddBehavior($name, $options);\r\n```\r\n\r\n**Get Behavior**\r\n\r\nGet a loaded [*Behavior*](#behaviors).\r\n\r\n- `$name` is a string representing the behavior name.\r\n\r\n```php\r\n$behavior = $model-\u003egetBehavior($name);\r\n```\r\n\r\n**Has Behavior**\r\n\r\nDetermine whether the *Model* has a [*Behavior*](#behaviors).\r\n\r\n- `$name` is a string representing the behavior name.\r\n\r\n```php\r\n$hasBehavior = $model-\u003ehasBehavior($name);\r\n```\r\n\r\n**Remove Behavior**\r\n\r\nRemove a [*Behavior*](#behaviors) from the *Model*.\r\n\r\n- `$name` is a string representing the behavior name.\r\n\r\n```php\r\n$model-\u003eremoveBehavior($name);\r\n```\r\n\r\n\r\n### Validation\r\n\r\n**Get Rules**\r\n\r\nGet the model [*RuleSet*](#rules).\r\n\r\n```php\r\n$rules = $model-\u003egetRules();\r\n```\r\n\r\nYou can build custom rules by specifying a `buildRules` method in your models.\r\n\r\n**Get Validator**\r\n\r\nGet the model [*Validator*](https://github.com/elusivecodes/FyreValidation).\r\n\r\n```php\r\n$validator = $model-\u003egetValidator();\r\n```\r\n\r\nYou can build a custom validator by specifying a `buildValidation` method in your models.\r\n\r\n**Set Rules**\r\n\r\nSet the model [*RuleSet*](#rules).\r\n\r\n- `$rules` is a [*RuleSet*](#rules).\r\n\r\n```php\r\n$model-\u003esetRules($rules);\r\n```\r\n\r\n**Set Validator**\r\n\r\nSet the model [*Validator*](https://github.com/elusivecodes/FyreValidation).\r\n\r\n- `$validator` is a [*Validator*](https://github.com/elusivecodes/FyreValidation).\r\n\r\n```php\r\n$model-\u003esetValidator($validator);\r\n```\r\n\r\n\r\n### Callbacks\r\n\r\nCallbacks can be defined in your models, allowing custom code to run or revert changes at various points during model operations.\r\n\r\n**After Delete**\r\n\r\nExecute a callback after entities are deleted.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterDelete(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the delete will not be performed and the transaction will be rolled back.\r\n\r\n**After Delete Commit**\r\n\r\nExecute a callback after entities are deleted and transaction is committed.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterDeleteCommit(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\n**After Find**\r\n\r\nExecute a callback after performing a find query.\r\n\r\n```php\r\nuse Fyre\\ORM\\Result;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterFind(Event $event, Result $result, array $options): Result {}\r\n```\r\n\r\n**After Rules**\r\n\r\nExecute a callback after model rules are processed.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterRules(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the save will not be performed.\r\n\r\n**After Parse**\r\n\r\nExecute a callback after parsing user data into an entity.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterParse(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\n**After Save**\r\n\r\nExecute a callback after entities are saved to the database.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterSave(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the save will not be performed and the transaction will be rolled back.\r\n\r\n**After Save Commit**\r\n\r\nExecute a callback after entities are saved to the database and transaction is committed.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function afterSaveCommit(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\n**Before Delete**\r\n\r\nExecute a callback before entities are deleted.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function beforeDelete(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the delete will not be performed.\r\n\r\n**Before Find**\r\n\r\nExecute a callback before performing a find query.\r\n\r\n```php\r\nuse Fyre\\Event\\Event;\r\nuse Fyre\\ORM\\Query;\r\n\r\npublic function beforeFind(Event $event, Query $query, array $options): Query {}\r\n```\r\n\r\n**Before Parse**\r\n\r\nExecute a callback before parsing user data into an entity.\r\n\r\n```php\r\nuse ArrayObject;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function beforeParse(Event $event, ArrayObject $data, array $options) {}\r\n```\r\n\r\n**Before Rules**\r\n\r\nBefore rules callback.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function beforeRules(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the save will not be performed.\r\n\r\n**Before Save**\r\n\r\nExecute a callback before entities are saved to the database.\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\nuse Fyre\\Event\\Event;\r\n\r\npublic function beforeSave(Event $event, Entity $entity, array $options) {}\r\n```\r\n\r\nIf the `$event` is stopped, the save will not be performed and the transaction will be rolled back.\r\n\r\n**Initialize**\r\n\r\nInitialize the model.\r\n\r\n```php\r\n$model-\u003einitialize();\r\n```\r\n\r\nThis method is called automatically when the model is loaded. You can define this method on your custom models to attach [*relationships*](#relationships) or [*behaviors*](#behaviors).\r\n\r\n\r\n## Queries\r\n\r\n**Get Model**\r\n\r\nGet the [*Model*](#models).\r\n\r\n```php\r\n$model = $query-\u003egetModel();\r\n```\r\n\r\n### Delete\r\n\r\nThe `\\Fyre\\ORM\\Queries\\DeleteQuery` class extends the [*DeleteQuery*](https://github.com/elusivecodes/FyreDB#delete) class. The table and alias will be automatically set from the *Model*.\r\n\r\n```php\r\n$model-\u003edeleteQuery()\r\n    -\u003ewhere($conditions)\r\n    -\u003eexecute();\r\n```\r\n\r\n### Insert\r\n\r\nThe `\\Fyre\\ORM\\Queries\\InsertQuery` class extends the [*InsertQuery*](https://github.com/elusivecodes/FyreDB#insert) class. The table will be automatically set from the *Model*.\r\n\r\n```php\r\n$model-\u003einsertQuery()\r\n    -\u003evalues($values)\r\n    -\u003eexecute();\r\n```\r\n\r\n### Replace\r\n\r\nThe `\\Fyre\\ORM\\Queries\\ReplaceQuery` class extends the [*ReplaceQuery*](https://github.com/elusivecodes/FyreDB#replace) class. The table will be automatically set from the *Model*.\r\n\r\n```php\r\n$model-\u003ereplaceQuery()\r\n    -\u003evalues($values)\r\n    -\u003eexecute();\r\n```\r\n\r\n### Select\r\n\r\nThe `\\Fyre\\ORM\\Queries\\SelectQuery` class extends the [*SelectQuery*](https://github.com/elusivecodes/FyreDB#select) class, while providing several additional methods and wrappers for relationship and entity mapping. The table and alias will be automatically set from the *Model*, and field names will be automatically aliased.\r\n\r\n```php\r\n$model-\u003eselectQuery()\r\n    -\u003eselect($fields)\r\n    -\u003ewhere($conditions)\r\n    -\u003eexecute();\r\n```\r\n\r\n**All**\r\n\r\nGet the [*Result*](#results).\r\n\r\n```php\r\n$results = $query-\u003eall();\r\n```\r\n\r\n**Clear Result**\r\n\r\nClear the buffered result.\r\n\r\n```php\r\n$query-\u003eclearResult();\r\n```\r\n\r\n**Contain**\r\n\r\nSet the contain relationships.\r\n\r\n- `$contain` is a string or array containing the relationships to contain.\r\n- `$overwrite` is a boolean indicating whether to overwrite existing contains, and will default to *false*.\r\n\r\n```php\r\n$query-\u003econtain($contain, $overwrite);\r\n```\r\n\r\n**Count**\r\n\r\nGet the result count.\r\n\r\n```php\r\n$count = $query-\u003ecount();\r\n```\r\n\r\n**Disable Auto Fields**\r\n\r\nDisable auto fields.\r\n\r\n```php\r\n$query-\u003edisableAutoFields();\r\n```\r\n\r\n**Disable Buffering**\r\n\r\nDisable result buffering.\r\n\r\n```php\r\n$query-\u003edisableBuffering();\r\n```\r\n\r\n**Enable Auto Fields**\r\n\r\nEnable auto fields.\r\n\r\n```php\r\n$query-\u003eenableAutoFields();\r\n```\r\n\r\n**Enable Buffering**\r\n\r\nEnable result buffering.\r\n\r\n```php\r\n$query-\u003eenableBuffering();\r\n```\r\n\r\n**First**\r\n\r\nGet the first result.\r\n\r\n```php\r\n$entity = $query-\u003efirst();\r\n```\r\n\r\n**Get Alias**\r\n\r\nGet the alias.\r\n\r\n```php\r\n$alias = $query-\u003egetAlias();\r\n```\r\n\r\n**Get Connection Type**\r\n\r\nGet the connection type.\r\n\r\n```php\r\n$connectionType = $query-\u003egetConnectionType();\r\n```\r\n\r\n**Get Contain**\r\n\r\nGet the contain array.\r\n\r\n```php\r\n$contain = $query-\u003egetContain();\r\n```\r\n\r\n**Get Matching**\r\n\r\nGet the matching array.\r\n\r\n```php\r\n$matching = $query-\u003egetMatching();\r\n```\r\n\r\n**Get Result**\r\n\r\nGet the [*Result*](#results).\r\n\r\n```php\r\n$result = $query-\u003egetResult();\r\n```\r\n\r\n**Inner Join With**\r\n\r\nINNER JOIN a relationship table.\r\n\r\n- `$contain` is a string representing the relationships to contain.\r\n- `$conditions` is an array containing additional join conditions.\r\n\r\n```php\r\n$query-\u003einnerJoinWith($contain, $conditions);\r\n```\r\n\r\n**Left Join With**\r\n\r\nLEFT JOIN a relationship table.\r\n\r\n- `$contain` is a string representing the relationships to contain.\r\n- `$conditions` is an array containing additional join conditions.\r\n\r\n```php\r\n$query-\u003eleftJoinWith($contain, $conditions);\r\n```\r\n\r\n**Matching**\r\n\r\nINNER JOIN a relationship table and load matching data.\r\n\r\n- `$contain` is a string representing the relationships to contain.\r\n- `$conditions` is an array containing additional join conditions.\r\n\r\n```php\r\n$query-\u003ematching($contain, $conditions);\r\n```\r\n\r\nThe matching data will be accessible via the `_matchingData` property.\r\n\r\n**Not Matching**\r\n\r\nLEFT JOIN a relationship table and exclude matching rows.\r\n\r\n- `$contain` is a string representing the relationships to contain.\r\n- `$conditions` is an array containing additional join conditions.\r\n\r\n```php\r\n$query-\u003enotMatching($contain, $conditions);\r\n```\r\n**To Array**\r\n\r\nGet the results as an array.\r\n\r\n```php\r\n$array = $query-\u003etoArray();\r\n```\r\n\r\n### Update\r\n\r\nThe `\\Fyre\\ORM\\Queries\\UpdateQuery` class extends the [*UpdateQuery*](https://github.com/elusivecodes/FyreDB#update) class. The table will be automatically set from the *Model*.\r\n\r\n```php\r\n$model-\u003eupdateQuery()\r\n    -\u003eset($values)\r\n    -\u003ewhere($conditions)\r\n    -\u003eexecute();\r\n```\r\n\r\n**Get Alias**\r\n\r\nGet the alias.\r\n\r\n```php\r\n$alias = $query-\u003egetAlias();\r\n```\r\n\r\n### Update Batch\r\n\r\nThe `\\Fyre\\ORM\\Queries\\UpdateBatchQuery` class extends the [*UpdateBatchQuery*](https://github.com/elusivecodes/FyreDB#update-batch) class. The table and alias will be automatically set from the *Model*, and field names will be automatically aliased.\r\n\r\n```php\r\n$model-\u003eupdateBatchQuery()\r\n    -\u003eset($values, $keys)\r\n    -\u003eexecute();\r\n```\r\n\r\n**Get Alias**\r\n\r\nGet the alias.\r\n\r\n```php\r\n$alias = $query-\u003egetAlias();\r\n```\r\n\r\n\r\n## Results\r\n\r\nThe `\\Fyre\\ORM\\Result` class wraps the [*ResultSet*](https://github.com/elusivecodes/FyreDB#results) class, and acts as a proxy for the [*Collection*](https://github.com/elusivecodes/FyreCollection) class, providing additional handling for entity mapping and eager loading contained results.\r\n\r\n\r\n## Relationships\r\n\r\nRelationships can be accessed directly as a property on the model, using the relationship name. Target model methods and properties can also be accessed directly from the relationship.\r\n\r\n**Build Joins**\r\n\r\nBuild join data.\r\n\r\n- `$options` is an array containing the join options, and will default to *[]*.\r\n\r\n```php\r\n$joins = $relationship-\u003ebuildJoins($options);\r\n```\r\n\r\n**Find Related**\r\n\r\nFind related data for entities.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$data` is an array containing the query data.\r\n\r\n```php\r\n$related = $relationship-\u003efindRelated($entities, $data);\r\n```\r\n\r\n**Get Binding Key**\r\n\r\nGet the binding key.\r\n\r\n```php\r\n$bindingKey = $relationship-\u003egetBindingKey();\r\n```\r\n\r\n**Get Conditions**\r\n\r\nGet the conditions.\r\n\r\n```php\r\n$conditions = $relationship-\u003egetConditions();\r\n```\r\n\r\n**Get Foreign Key**\r\n\r\nGet the foreign key.\r\n\r\n```php\r\n$foreignKey = $relationship-\u003egetForeignKey();\r\n```\r\n\r\n**Get Join Type**\r\n\r\nGet the join type.\r\n\r\n```php\r\n$joinType = $relationship-\u003egetJoinType();\r\n```\r\n\r\n**Get Name**\r\n\r\nGet the relationship name.\r\n\r\n```php\r\n$name = $relationship-\u003egetName();\r\n```\r\n\r\n**Get Property**\r\n\r\nGet the relationship property name.\r\n\r\n```php\r\n$propertyName = $relationship-\u003egetProperty();\r\n```\r\n\r\n**Get Source**\r\n\r\nGet the source [*Model*](#models).\r\n\r\n```php\r\n$source = $relationship-\u003egetSource();\r\n```\r\n\r\n**Get Strategy**\r\n\r\nGet the select strategy.\r\n\r\n```php\r\n$strategy = $relationship-\u003egetStrategy();\r\n```\r\n\r\n**Get Target**\r\n\r\nGet the target [*Model*](#models).\r\n\r\n```php\r\n$target = $relationship-\u003egetTarget();\r\n```\r\n\r\n**Has Multiple**\r\n\r\nDetermine whether the relationship has multiple related items.\r\n\r\n```php\r\n$hasMultiple = $relationship-\u003ehasMultiple();\r\n```\r\n\r\n**Is Dependent**\r\n\r\nDetermine whether the target is dependent.\r\n\r\n```php\r\n$isDependent = $relationship-\u003eisDependent();\r\n```\r\n\r\n**Is Owning Side**\r\n\r\nDetermine whether the source is the owning side of the relationship.\r\n\r\n```php\r\n$isOwningSide = $relationship-\u003eisOwningSide();\r\n```\r\n\r\n**Load Related**\r\n\r\nLoad related data for entities.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$data` is an array containing the query data.\r\n- `$query` is a [*SelectQuery*](#select) (that produced the entities), and will default to *null*.\r\n\r\n```php\r\n$relationship-\u003eloadRelated($entities, $data);\r\n```\r\n\r\n**Save Related**\r\n\r\nSave related data for an entity.\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n```php\r\n$result = $relationship-\u003esaveRelated($entity);\r\n```\r\n\r\n**Set Binding Key**\r\n\r\nSet the binding key.\r\n\r\n- `$bindingKey` is a string representing the binding key.\r\n\r\n```php\r\n$relationship-\u003esetBindingKey($bindingKey);\r\n```\r\n\r\n**Set Conditions**\r\n\r\nSet the conditions.\r\n\r\n- `$conditions` is an array containing additional conditions.\r\n\r\n```php\r\n$relationship-\u003esetConditions($conditions);\r\n```\r\n\r\n**Set Dependent**\r\n\r\nSet whether the target is dependent.\r\n\r\n- `$dependent` is a boolean indicating whether to recursively delete related data.\r\n\r\n```php\r\n$relationship-\u003esetDependent($dependent);\r\n```\r\n\r\n**Set Foreign Key**\r\n\r\nSet the foreign key.\r\n\r\n- `$foreignKey` is a string representing the foreign key key.\r\n\r\n```php\r\n$relationship-\u003esetForeignKey($foreignKey);\r\n```\r\n\r\n**Set Join Type**\r\n\r\nSet the join type.\r\n\r\n- `$joinType` is a string representing the type of join.\r\n\r\n```php\r\n$relationship-\u003esetJoinType($joinType);\r\n```\r\n\r\n**Set Property**\r\n\r\nSet the property name.\r\n\r\n- `$propertyName` is a string representing the entity property name.\r\n\r\n```php\r\n$relationship-\u003esetProperty($propertyName);\r\n```\r\n\r\n**Set Source**\r\n\r\nSet the source [*Model*](#models).\r\n\r\n- `$source` is a [*Model*](#models).\r\n\r\n```php\r\n$relationship-\u003esetSource($source);\r\n```\r\n\r\n**Set Strategy**\r\n\r\nSet the select strategy.\r\n\r\n- `$strategy` is a string representing the select strategy.\r\n\r\n```php\r\n$relationship-\u003esetStrategy($strategy);\r\n```\r\n\r\n**Set Target**\r\n\r\nSet the target [*Model*](#models).\r\n\r\n- `$target` is a [*Model*](#models).\r\n\r\n```php\r\n$relationship-\u003esetTarget($target);\r\n```\r\n\r\n**Unlink All**\r\n\r\nRemove related data from entities.\r\n\r\n- `$entities` is an array or *Traversable* containing the entities.\r\n- `$options` is an array containing delete options.\r\n\r\n```php\r\n$result = $relationship-\u003eunlinkAll($entities, $options);\r\n```\r\n\r\n### Belongs To\r\n\r\n- `$name` is a string representing the relationship name.\r\n- `$data` is an array containing relationship data.\r\n    - `classAlias` is a string representing the target class alias, and will default to the relationship name.\r\n    - `propertyName` is a string representing the entity property name, and will default to the snake case form of the singular relationship name.\r\n    - `foreignKey` is a string representing the foreign key column in the current table, and will default to the snake case singular name of the target alias (suffixed with *\"_id\"*).\r\n    - `bindingKey` is a string representing the matching column in the target table, and will default to the primary key.\r\n    - `strategy` must be either \"*join*\" or \"*select*\", and will default to \"*join*\".\r\n    - `conditions` is an array containing additional conditions.\r\n    - `joinType` is a string representing the type of join, and will default to \"*LEFT*\".\r\n\r\n```php\r\n$model-\u003ebelongsTo($name, $data);\r\n```\r\n\r\n### Has Many\r\n\r\n- `$name` is a string representing the relationship name.\r\n- `$data` is an array containing relationship data.\r\n    - `classAlias` is a string representing the target class alias, and will default to the relationship name.\r\n    - `propertyName` is a string representing the entity property name, and will default to the snake case form of the relationship name.\r\n    - `foreignKey` is a string representing the foreign key column in the target table, and will default to the snake case singular name of the current alias (suffixed with *\"_id\"*).\r\n    - `bindingKey` is a string representing the matching column in the current table, and will default to the primary key.\r\n    - `strategy` must be either \"*select*\" or \"*subquery*\", and will default to \"*select*\".\r\n    - `saveStrategy` must be either \"*append*\" or \"*replace*\", and will default to \"*append*\".\r\n    - `conditions` is an array containing additional conditions.\r\n    - `sort` is an array or string representing the fields to order by, and will default to *null*.\r\n    - `dependent` is a boolean indicating whether to recursively delete related data, and will default to *false*.\r\n\r\n```php\r\n$model-\u003ehasMany($name, $data);\r\n```\r\n\r\n**Get Save Strategy**\r\n\r\nGet the save strategy.\r\n\r\n```php\r\n$saveStrategy = $relationship-\u003egetSaveStrategy();\r\n```\r\n\r\n**Get Sort**\r\n\r\nGet the sort order.\r\n\r\n```php\r\n$sort = $relationship-\u003egetSort();\r\n```\r\n\r\n**Set Save Strategy**\r\n\r\nSet the save strategy.\r\n\r\n- `$saveStrategy` is a string representing the save strategy.\r\n\r\n```php\r\n$relationship-\u003esetSaveStrategy($saveStrategy);\r\n```\r\n\r\n**Set Sort**\r\n\r\nSet the sort order.\r\n\r\n- `$sort` is an array or string representing the fields to order by.\r\n\r\n```php\r\n$relationship-\u003esetSort($sort);\r\n```\r\n\r\n### Has One\r\n\r\n- `$name` is a string representing the relationship name.\r\n- `$data` is an array containing relationship data.\r\n    - `classAlias` is a string representing the target class alias, and will default to the relationship name.\r\n    - `propertyName` is a string representing the entity property name, and will default to the snake case form of the singular relationship name.\r\n    - `foreignKey` is a string representing the foreign key column in the target table, and will default to the snake case singular name of the current alias (suffixed with *\"_id\"*).\r\n    - `bindingKey` is a string representing the matching column in the current table, and will default to the primary key.\r\n    - `strategy` must be either \"*join*\" or \"*select*\", and will default to \"*join*\".\r\n    - `conditions` is an array containing additional conditions.\r\n    - `joinType` is a string representing the type of join, and will default to \"*LEFT*\".\r\n    - `dependent` is a boolean indicating whether to recursively delete related data, and will default to *false*.\r\n\r\n```php\r\n$model-\u003ehasOne($name, $data);\r\n```\r\n\r\n### Many To Many\r\n\r\nWhen loading results, the join table data will be accessible via the `_joinData` property.\r\n\r\n- `$name` is a string representing the relationship name.\r\n- `$data` is an array containing relationship data.\r\n    - `classAlias` is a string representing the target class alias, and will default to the relationship name.\r\n    - `through` is a string representing the join alias, and will default to the concatenated form of the current alias and relationship name (sorted alphabetically).\r\n    - `propertyName` is a string representing the entity property name, and will default to the snake case form of the relationship name.\r\n    - `foreignKey` is a string representing the foreign key column in the join table, and will default to the snake case singular name of the current alias (suffixed with *\"_id\"*).\r\n    - `targetForeignKey` is a string representing the target foreign key column in the join table, and will default to the snake case singular name of the relationship name (suffixed with *\"_id\"*).\r\n    - `bindingKey` is a string representing the matching column in the current table, and will default to the primary key.\r\n    - `strategy` must be either \"*select*\" or \"*subquery*\", and will default to \"*select*\".\r\n    - `saveStrategy` must be either \"*append*\" or \"*replace*\", and will default to \"*replace*\".\r\n    - `sort` is an array or string representing the fields to order by, and will default to *null*.\r\n    - `conditions` is an array containing additional conditions.\r\n\r\n```php\r\n$model-\u003emanyToMany($name, $data);\r\n```\r\n\r\n**Get Junction**\r\n\r\nGet the junction [*Model*](#models).\r\n\r\n```php\r\n$junction = $relationship-\u003egetJunction();\r\n```\r\n\r\n**Get Save Strategy**\r\n\r\nGet the save strategy.\r\n\r\n```php\r\n$saveStrategy = $relationship-\u003egetSaveStrategy();\r\n```\r\n\r\n**Get Sort**\r\n\r\nGet the sort order.\r\n\r\n```php\r\n$sort = $relationship-\u003egetSort();\r\n```\r\n\r\n**Get Source Relationship**\r\n\r\nGet the source relationship.\r\n\r\n```php\r\n$sourceRelationship = $relationship-\u003egetSourceRelationship();\r\n```\r\n\r\n**Get Target Foreign Key**\r\n\r\nGet the target foreign key.\r\n\r\n```php\r\n$targetForeignKey = $relationship-\u003egetTargetForeignKey();\r\n```\r\n\r\n**Get Target Relationship**\r\n\r\nGet the target relationship.\r\n\r\n```php\r\n$targetRelationship = $relationship-\u003egetTargetRelationship();\r\n```\r\n\r\n**Set Junction**\r\n\r\nSet the junction [*Model*](#models).\r\n\r\n- `$junction` is a [*Model*](#models).\r\n\r\n```php\r\n$relationship-\u003esetJunction($junction);\r\n```\r\n\r\n**Set Save Strategy**\r\n\r\nSet the save strategy.\r\n\r\n- `$saveStrategy` is a string representing the save strategy.\r\n\r\n```php\r\n$relationship-\u003esetSaveStrategy($saveStrategy);\r\n```\r\n\r\n**Set Sort**\r\n\r\nSet the sort order.\r\n\r\n- `$sort` is an array or string representing the fields to order by.\r\n\r\n```php\r\n$relationship-\u003esetSort($sort);\r\n```\r\n\r\n**Set Target Foreign Key**\r\n\r\nSet the target foreign key.\r\n\r\n- `$targetForeignKey` is a string representing the target foreign key column in the join table.\r\n\r\n```php\r\n$relationship-\u003esetTargetForeignKey($targetForeignKey);\r\n```\r\n\r\n\r\n## Behavior Registry\r\n\r\n```php\r\nuse Fyre\\ORM\\BehaviorRegistry;\r\n```\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$behaviorRegistry = new BehaviorRegistry($container);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *BehaviorRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(BehaviorRegistry::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$behaviorRegistry = $container-\u003euse(BehaviorRegistry::class);\r\n```\r\n\r\n### Behavior Registry Methods\r\n\r\n**Add Namespace**\r\n\r\nAdd a namespace for automatically loading behaviors.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$behaviorRegistry-\u003eaddNamespace($namespace);\r\n```\r\n\r\n**Build**\r\n\r\nBuild a behavior.\r\n\r\n- `$name` is a string representing the behavior name.\r\n- `$model` is a [*Model*](#models).\r\n- `$options` is an array containing the behavior options, and will default to *[]*.\r\n\r\n```php\r\n$behavior = $behaviorRegistry-\u003ebuild($name, $model, $options);\r\n```\r\n\r\n**Clear**\r\n\r\nClear all namespaces and behaviors.\r\n\r\n```php\r\n$behaviorRegistry-\u003eclear();\r\n```\r\n\r\n**Find**\r\n\r\nFind a behavior class.\r\n\r\n- `$name` is a string representing the behavior name.\r\n\r\n```php\r\n$className = $behaviorRegistry-\u003efind($name);\r\n```\r\n\r\n**Get Namespaces**\r\n\r\nGet the namespaces.\r\n\r\n```php\r\n$namespaces = $behaviorRegistry-\u003egetNamespaces();\r\n```\r\n\r\n**Has Namespace**\r\n\r\nDetermine whether a namespace exists.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$hasNamespace = $behaviorRegistry-\u003ehasNamespace($namespace);\r\n```\r\n\r\n**Remove Namespace**\r\n\r\nRemove a namespace.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$behaviorRegistry-\u003eremoveNamespace($namespace);\r\n```\r\n\r\n\r\n## Behaviors\r\n\r\nBehaviors must be attached to a [*Model*](#models) using the `addBehavior` method. Behavior methods can then be called directly on the model.\r\n\r\nCustom behaviors can be created by extending `\\Fyre\\ORM\\Behavior`, suffixing the class name with \"*Behavior*\", and ensuring the `__construct` method accepts [*Model*](#models) as the argument (and optionally an `$options` array as the second parameter).\r\n\r\nBehaviors can also include [callbacks](#callbacks) that will be executed during model operations.\r\n\r\n**Get Config**\r\n\r\nGet the configuration options.\r\n\r\n```php\r\n$config = $behavior-\u003egetConfig();\r\n```\r\n\r\n**Get Model**\r\n\r\nGet the [*Model*](#models).\r\n\r\n```php\r\n$model = $behavior-\u003egetModel();\r\n```\r\n\r\n### Timestamp\r\n\r\nThe timestamp behavior provided a simple way to automatically update created/modified timestamps when saving data via models.\r\n\r\n- `$options` is an array containing behavior options.\r\n    - `createdField` is a string representing the created field name, and will default to \"*created*\".\r\n    - `modifiedField` is a string representing the modified field name, and will default to \"*modified*\".\r\n\r\n```php\r\n$model-\u003eaddBehavior('Timestamp', $options);\r\n```\r\n\r\n\r\n## Rules\r\n\r\n**Add**\r\n\r\nAdd a rule.\r\n\r\n- `$rule` is a *Closure*, that accepts an [*Entity*](https://github.com/elusivecodes/FyreEntity) as the first argument, and should return *false* if the validation failed.\r\n\r\n```php\r\n$rules-\u003eadd($rule);\r\n```\r\n\r\n**Exists In**\r\n\r\nCreate an \"exists in\" rule.\r\n\r\n- `$fields` is an array containing the fields.\r\n- `$name` is the name of the relationship.\r\n- `$options` is an array containing the rule options.\r\n    - `targetFields` is an array containing fields to match in the target table, and will default to the primary key(s).\r\n    - `callback` is a *Closure*, that accepts the [*SelectQuery*](#select) as an argument.\r\n    - `allowNullableNulls` is a boolean indicating whether to allow nullable nulls, and will default to *null*.\r\n    - `message` is a string representing the error message, and will default to the [*Lang*](https://github.com/elusivecodes/FyreLang) value for \"*RuleSet.existsIn*\".\r\n\r\n```php\r\n$rules-\u003eexistsIn($fields, $name, $options);\r\n```\r\n\r\n**Is Clean**\r\n\r\nCreate an \"is clean\" rule.\r\n\r\n- `$options` is an array containing the rule options.\r\n- `$fields` is an array containing the fields.\r\n    - `message` is a string representing the error message, and will default to the [*Lang*](https://github.com/elusivecodes/FyreLang) value for \"*RuleSet.isClean*\".\r\n\r\n```php\r\n$rules-\u003eisClean($fields, $options);\r\n```\r\n\r\n**Is Unique**\r\n\r\nCreate an \"is unique\" rule.\r\n\r\n- `$fields` is an array containing the fields.\r\n- `$options` is an array containing the rule options.\r\n    - `callback` is a *Closure*, that accepts the [*SelectQuery*](#select) as an argument.\r\n    - `allowMultipleNulls` is a boolean indicating whether to allow multiple nulls, and will default to *true*.\r\n    - `message` is a string representing the error message, and will default to the [*Lang*](https://github.com/elusivecodes/FyreLang) value for \"*RuleSet.isUnique*\".\r\n\r\n```php\r\n$rules-\u003eisUnique($fields, $options);\r\n```\r\n\r\n**Validate**\r\n\r\nValidate an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n- `$entity` is an [*Entity*](https://github.com/elusivecodes/FyreEntity).\r\n\r\n```php\r\n$rules-\u003evalidate($entity);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyreorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreorm/lists"}