-
Docs
Backend
-
Behaviors
-
Classes
-
Controllers
-
Database
-
Seeds
-
-
Facades
-
FormWidgets
-
Helpers
-
Exception
- Backend
-
-
Models
-
ReportWidgets
-
Skins
-
Traits
-
Widgets
- ServiceProvider
-
-
Cms
-
Classes
- Asset
- AutoDatasource
- CmsCompoundObject
- CmsController
- CmsException
- CmsObject
- CmsObjectCollection
- CodeBase
- CodeParser
- ComponentBase
- ComponentHelpers
- ComponentManager
- ComponentPartial
- Content
- Controller
- Layout
- LayoutCode
- MediaLibrary
- MediaLibraryItem
- MediaViewHelper
- Meta
- ObjectMemoryCache
- Page
- PageCode
- Partial
- PartialCode
- PartialStack
- Router
- Theme
- ThemeManager
-
Components
-
Contracts
-
Controllers
-
Facades
-
FormWidgets
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ComponentNode
- ComponentTokenParser
- ContentNode
- ContentTokenParser
- DebugExtension
- DefaultNode
- DefaultTokenParser
- Extension
- FlashNode
- FlashTokenParser
- FrameworkNode
- FrameworkTokenParser
- Loader
- PageNode
- PageTokenParser
- PartialNode
- PartialTokenParser
- PlaceholderNode
- PlaceholderTokenParser
- PutNode
- PutTokenParser
- ScriptsNode
- ScriptsTokenParser
- StylesNode
- StylesTokenParser
-
Widgets
- ServiceProvider
-
-
System
-
Behaviors
-
Classes
-
Console
-
Controllers
-
Database
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- ServiceProvider
-
-
Events
-
backend
-
ajax
-
filter
-
form
-
list
-
menu
-
page
-
user
-
-
cms
-
ajax
-
block
-
combiner
-
component
-
object
-
page
-
router
-
template
-
theme
-
-
halcyon
-
datasource
-
-
mailer
-
media
-
model
-
system
-
assets
-
console
-
mirror
-
theme
-
-
reportwidgets
-
settings
- extendConfigFile
-
-
translator
-
-
Library
-
Argon
-
Auth
-
Models
- AuthException
- Manager
-
-
Config
-
Cookie
-
Middleware
-
-
Database
-
Attach
-
Behaviors
-
Concerns
-
Connections
-
Connectors
-
Models
-
Relations
-
Schema
-
Traits
-
Updates
- README
- Builder
- Collection
- DatabaseServiceProvider
- DataFeed
- Dongle
- MemoryCache
- Model
- ModelBehavior
- ModelException
- NestedTreeScope
- Pivot
- QueryBuilder
- SortableScope
- TreeCollection
- Updater
-
-
Events
-
Exception
-
Extension
-
Filesystem
-
Flash
-
Foundation
-
Bootstrap
-
Console
-
Exception
-
Http
-
Middleware
- Kernel
-
-
Providers
- Application
- Maker
-
-
Halcyon
-
Datasource
-
Exception
-
Processors
-
Traits
- README
- Builder
- Collection
- HalcyonServiceProvider
- MemoryCacheManager
- MemoryRepository
- Model
-
-
Html
-
Mail
-
Network
-
Parse
-
Router
-
Scaffold
-
Support
-
Translation
-
- Documentation
- API
- Library
- Database
- Concerns
- HasRelationships
October\Rain\Database\Concerns\HasRelationships
Source: ~/vendor/october/rain/src/Database/Concerns/HasRelationships.php
Public properties
public array $hasMany
Cleaner declaration of relationships. Uses a similar approach to the relation methods used by Eloquent, but as separate properties that make the class file less cluttered.
It should be declared with keys as the relation name, and value being a mixed array. The relation type $morphTo does not include a classname as the first value.
Example: class Order extends Model { protected $hasMany = [ 'items' => 'Item' ]; }
public $hasOne
protected $hasOne = [ 'owner' => ['User', 'key' => 'user_id'] ];
public $belongsTo
protected $belongsTo = [ 'parent' => ['Category', 'key' => 'parent_id'] ];
public $belongsToMany
protected $belongsToMany = [ 'groups' => ['Group', 'table'=> 'join_groups_users'] ];
public $morphTo
protected $morphTo = [ 'pictures' => [] ];
public $morphOne
protected $morphOne = [ 'log' => ['History', 'name' => 'user'] ];
public $morphMany
protected $morphMany = [ 'log' => ['History', 'name' => 'user'] ];
public $morphToMany
protected $morphToMany = [ 'tag' => ['Tag', 'table' => 'tagables', 'name' => 'tagable'] ];
public $morphedByMany
public $attachOne
protected $attachOne = [ 'picture' => ['October\Rain\Database\Attach\File', 'public' => false] ];
public $attachMany
protected $attachMany = [ 'pictures' => ['October\Rain\Database\Attach\File', 'name'=> 'imageable'] ];
public $hasManyThrough
protected $attachMany = [ 'pictures' => ['Picture', 'name'=> 'imageable'] ];
Protected properties
protected static array $relationTypes
Excepted relationship types, used to cycle and verify relationships.
Public methods
public October\Rain\Database\Relations\MorphMany attachMany($related, $isPublic=NULL, $localKey=NULL, $relationName=NULL)
Define an attachment one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $isPublic
- $localKey
- $relationName
public October\Rain\Database\Relations\MorphOne attachOne($related, $isPublic=true, $localKey=NULL, $relationName=NULL)
Define an attachment one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $isPublic
- $localKey
- $relationName
public October\Rain\Database\Relations\BelongsTo belongsTo($related, $foreignKey=NULL, $parentKey=NULL, $relationName=NULL)
Define an inverse one-to-one or many relationship. Overridden from {@link Eloquent\Model} to allow the usage of the intermediary methods to handle the {@link $relationsData} array.
Parameters
- $related
- $foreignKey
- $parentKey
- $relationName
public October\Rain\Database\Relations\BelongsToMany belongsToMany($related, $table=NULL, $primaryKey=NULL, $foreignKey=NULL, $parentKey=NULL, $relatedKey=NULL, $relationName=NULL)
Define a many-to-many relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $table
- $primaryKey
- $foreignKey
- $parentKey
- $relatedKey
- $relationName
public array getRelationDefinition(string $name)
Returns relationship details from a supplied name.
Parameters
- string $name - Relation name
public array getRelationDefinitions()
Returns relationship details for all relations defined on this model.
public string getRelationType(string $name)
Returns a relationship type based on a supplied name.
Parameters
- string $name - Relation name
public void getRelationValue($relationName)
Returns a relation key value(s), not as an object.
Parameters
- $relationName
public October\Rain\Database\Relations\HasMany hasMany($related, $primaryKey=NULL, $localKey=NULL, $relationName=NULL)
Define a one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $primaryKey
- $localKey
- $relationName
public October\Rain\Database\Relations\HasMany hasManyThrough($related, $through, $primaryKey=NULL, $throughKey=NULL, $localKey=NULL, $secondLocalKey=NULL, $relationName=NULL)
Define a has-many-through relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $through
- $primaryKey
- $throughKey
- $localKey
- $secondLocalKey
- $relationName
public October\Rain\Database\Relations\HasOne hasOne($related, $primaryKey=NULL, $localKey=NULL, $relationName=NULL)
Define a one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $primaryKey
- $localKey
- $relationName
public bool hasRelation(string $name)
Checks if model has a relationship by supplied name.
Parameters
- string $name - Relation name
public boolean isRelationPushable(string $name)
Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.
Parameters
- string $name - Relation name
public string makeRelation(string $name)
Returns a relation class object
Parameters
- string $name - Relation name
public October\Rain\Database\Relations\MorphMany morphMany($related, $name, $type=NULL, $id=NULL, $localKey=NULL, $relationName=NULL)
Define a polymorphic one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $name
- $type
- $id
- $localKey
- $relationName
public October\Rain\Database\Relations\MorphOne morphOne($related, $name, $type=NULL, $id=NULL, $localKey=NULL, $relationName=NULL)
Define a polymorphic one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $name
- $type
- $id
- $localKey
- $relationName
public October\Rain\Database\Relations\BelongsTo morphTo($name=NULL, $type=NULL, $id=NULL)
Define an polymorphic, inverse one-to-one or many relationship. Overridden from {@link Eloquent\Model} to allow the usage of the intermediary methods to handle the relation.
Parameters
- $name
- $type
- $id
public October\Rain\Database\Relations\MorphToMany morphToMany($related, $name, $table=NULL, $primaryKey=NULL, $foreignKey=NULL, $parentKey=NULL, $relatedKey=NULL, $inverse=false, $relationName=NULL)
Define a polymorphic many-to-many relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $name
- $table
- $primaryKey
- $foreignKey
- $parentKey
- $relatedKey
- $inverse
- $relationName
public October\Rain\Database\Relations\MorphToMany morphedByMany($related, $name, $table=NULL, $primaryKey=NULL, $foreignKey=NULL, $parentKey=NULL, $relatedKey=NULL, $relationName=NULL)
Define a polymorphic many-to-many inverse relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
Parameters
- $related
- $name
- $table
- $primaryKey
- $foreignKey
- $parentKey
- $relatedKey
- $relationName
Protected methods
protected void getRelationCaller()
Finds the calling function name from the stack trace.
protected array getRelationDefaults(string $type)
Returns default relation arguments for a given type.
Parameters
- string $type - Relation type
protected Illuminate\Database\Eloquent\Relations\Relation handleRelation(string $relationName)
Looks for the relation and does the correct magic as Eloquent would require inside relation methods. For more information, read the documentation of the mentioned property.
Parameters
- string $relationName - The relation key, camel-case version
protected Illuminate\Database\Eloquent\Relations\MorphTo morphEagerTo(string $name, string $type, string $id)
Define a polymorphic, inverse one-to-one or many relationship.
Parameters
- string $name
- string $type
- string $id
protected Illuminate\Database\Eloquent\Relations\MorphTo morphInstanceTo(string $target, string $name, string $type, string $id)
Define a polymorphic, inverse one-to-one or many relationship.
Parameters
- string $target
- string $name
- string $type
- string $id
protected void setRelationValue($relationName, $value)
Sets a relation value directly from its attribute.
Parameters
- $relationName
- $value
protected void validateRelationArgs($relationName, $optional, $required=array())
Validate relation supplied arguments.
Parameters
- $relationName
- $optional
- $required