-
Backend
-
Behaviors
-
FormController
-
ImportExportController
-
ListController
-
RelationController
- FormController
- ImportExportController
- ListController
- RelationController
- ReorderController
- UserPreferencesModel
-
-
Classes
-
Dashboard
-
NavigationManager
-
WidgetManager
- AuthManager
- BackendController
- Controller
- ControllerBehavior
- DashboardManager
- DashboardWidgetBase
- FilterScope
- FilterWidgetBase
- FormField
- FormTabs
- FormWidgetBase
- ListColumn
- LoginCustomization
- MainMenuItem
- NavigationManager
- ReportDataSourceBase
- ReportDataSourceManager
- ReportWidgetBase
- RoleManager
- RolePermission
- SettingsController
- SideMenuItem
- Skin
- StaticReportWidgetContainer
- VueComponentBase
- WidgetBase
- WidgetManager
- WildcardController
-
-
Controllers
-
Database
-
Facades
-
FilterWidgets
-
FormWidgets
-
Helpers
-
Models
-
BrandSetting
-
ExportModel
-
ImportModel
- AccessLog
- BrandSetting
- Dashboard
- EditorSetting
- ExportModel
- ImportModel
- Preference
- ReportDataCache
- User
- UserGroup
- UserPreference
- UserPreferenceModel
- UserRole
- UserThrottle
-
-
ReportWidgets
-
Skins
-
Traits
-
VueComponents
-
Widgets
-
Filter
-
Form
-
Lists
-
Table
- Filter
- Form
- Lists
- ListStructure
- ReportContainer
- RoleImpersonator
- Search
- SiteSwitcher
- Table
- Toolbar
-
- ServiceProvider
-
-
Cms
-
Classes
-
Controller
-
EditorExtension
-
Layout
-
Page
-
Partial
-
Theme
- AjaxResponse
- Asset
- CmsCompoundObject
- CmsController
- CmsDemoTrafficDataGenerator
- CmsException
- CmsObject
- CmsObjectCache
- CmsObjectCollection
- CmsReportDataSource
- CmsStatusDataSource
- CodeBase
- CodeParser
- ComponentBase
- ComponentBehavior
- ComponentHelpers
- ComponentManager
- ComponentModuleBase
- ComponentPartial
- Content
- Controller
- EditorExtension
- Layout
- LayoutCode
- Meta
- Page
- PageCode
- PageManager
- Partial
- PartialCode
- PartialStack
- PartialWatcher
- Router
- Snippet
- SnippetManager
- Theme
- ThemeManager
- ThisVariable
- TrafficLogger
-
-
Components
-
Console
-
Controllers
-
Database
-
Facades
-
FormWidgets
-
Helpers
-
Models
-
ReportWidgets
-
Traits
-
Twig
- AjaxPartialTokenParser
- ComponentNode
- ComponentTokenParser
- ContentNode
- ContentTokenParser
- DebugExtension
- DefaultNode
- DefaultTokenParser
- Extension
- FlashNode
- FlashTokenParser
- FrameworkNode
- FrameworkTokenParser
- GetAttrAdjuster
- GetAttrNode
- Loader
- MetaNode
- MetaTokenParser
- PageNode
- PageTokenParser
- PartialNode
- PartialTokenParser
- PlaceholderNode
- PlaceholderTokenParser
- PutNode
- PutTokenParser
- ScriptsNode
- ScriptsTokenParser
- StylesNode
- StylesTokenParser
-
VueComponents
-
Widgets
- ServiceProvider
-
-
Editor
-
Behaviors
-
Classes
-
Controllers
-
Traits
-
VueComponents
- ServiceProvider
-
-
Media
-
Classes
-
Controllers
-
FormWidgets
-
Helpers
-
Twig
-
Widgets
- ServiceProvider
-
-
System
-
Behaviors
-
Classes
-
PresetManager
-
SiteManager
-
UiManager
-
UpdateManager
- AppBase
- CombineAssets
- DependencyResolver
- DriverBehavior
- ErrorHandler
- MailManager
- ManifestCache
- MarkupExtensionItem
- MarkupManager
- ModelBehavior
- PagerElement
- PluginBase
- PluginManager
- PresetManager
- ProductDetail
- RateLimiter
- ResizeImageItem
- ResizeImages
- SettingsManager
- SettingsMenuItem
- SiteManager
- SystemController
- SystemReportDataSource
- UiElement
- UiManager
- UpdateManager
- VersionManager
-
-
Console
- ComposerScript
- OctoberAbout
- OctoberDown
- OctoberFresh
- OctoberMigrate
- OctoberMirror
- OctoberOptimize
- OctoberPasswd
- OctoberUp
- OctoberUpdate
- OctoberUtil
- OctoberUtilCommands
- OctoberUtilPatches
- OctoberUtilRefitLang
- PluginCheck
- PluginDisable
- PluginEnable
- PluginInstall
- PluginList
- PluginRefresh
- PluginRemove
- PluginSeed
- PluginTest
- ProjectSync
-
Controllers
-
Database
-
Facades
-
Helpers
-
Middleware
-
Models
-
ReportWidgets
-
Traits
-
Twig
-
Widgets
- ServiceProvider
-
-
Tailor
-
Behaviors
-
Classes
-
Blueprint
-
BlueprintIndexer
-
EditorExtension
-
Relations
-
SchemaBuilder
-
Scopes
- Blueprint
- BlueprintCollection
- BlueprintErrorData
- BlueprintException
- BlueprintIndexer
- BlueprintModel
- BlueprintVerifier
- ComponentVariable
- ContentFieldBase
- EditorExtension
- FieldManager
- Fieldset
- NavigationItem
- PermissionItem
- RecordIndexer
- SchemaBuilder
- SchemaPruner
-
-
Components
-
Console
-
ContentFields
-
Controllers
-
Models
-
EntryRecord
-
GlobalRecord
-
RecordImport
- ContentSchema
- EntryRecord
- GlobalRecord
- NestedFormItem
- PreviewToken
- RecordExport
- RecordImport
- RepeaterItem
-
-
Traits
-
VueComponents
- ServiceProvider
-
-
Events
-
backend
-
ajax
-
brand
-
files
-
filter
-
form
-
list
-
menu
-
page
-
roles
-
site
-
user
-
-
cms
-
ajax
-
block
-
combiner
-
component
-
internalTrafficStatistics
-
object
-
page
-
pageLookup
-
resizer
-
router
-
sitePicker
-
template
-
theme
- extendTwig
-
-
deferredBinding
-
editor
-
extension
-
-
exception
-
halcyon
-
datasource
-
-
mailer
-
media
-
model
-
auth
-
filter
-
form
-
relation
-
/docs/api/model/relation/add
-
/docs/api/model/relation/associate
- attach
-
/docs/api/model/relation/beforeadd
-
/docs/api/model/relation/beforeassociate
- beforeAttach
- beforeDetach
-
/docs/api/model/relation/beforedissociate
-
/docs/api/model/relation/beforeremove
- detach
-
/docs/api/model/relation/dissociate
-
/docs/api/model/relation/remove
-
-
/docs/api/model/afterboot
-
/docs/api/model/aftercreate
-
/docs/api/model/afterdelete
-
/docs/api/model/afterfetch
-
/docs/api/model/afterinit
- afterRelation
- afterRestore
-
/docs/api/model/aftersave
- afterTrash
-
/docs/api/model/afterupdate
- afterValidate
-
/docs/api/model/beforecreate
-
/docs/api/model/beforedelete
-
/docs/api/model/beforefetch
- beforeGetAttribute
- beforeRelation
- beforeReplicate
- beforeRestore
-
/docs/api/model/beforesave
- beforeSetAttribute
-
/docs/api/model/beforeupdate
- beforeValidate
- extendBlueprint
- getAttribute
- newInstance
- saveInternal
- setAttribute
-
-
pages
-
snippet
-
-
site
-
system
-
assets
- beforeAddAsset
-
/docs/api/system/assets/beforebundleasset
-
console
-
mirror
-
-
mail
-
reportwidgets
-
resizer
-
settings
-
site
-
updater
- extendConfigFile
- extendTwig
-
-
tailor
-
user
-
-
Library
-
Argon
-
Assetic
-
Asset
-
Cache
-
Exception
-
Factory
-
Filter
-
Traits
-
Util
- README
- AsseticServiceProvider
- AssetManager
- AssetWriter
- Combiner
- FilterManager
-
-
Auth
-
Combine
-
Composer
-
Config
-
Database
-
Attach
-
Concerns
-
Connections
-
Connectors
-
Factories
-
Models
-
Relations
-
Schema
-
Scopes
-
Traits
-
Updates
- README
- Builder
- Collection
- DatabaseServiceProvider
- Dongle
- ExpandoModel
- MigrationServiceProvider
- Model
- ModelBehavior
- ModelException
- MorphPivot
- NestedTreeScope
- Pivot
- QueryBuilder
- Replicator
- SortableScope
- TreeCollection
- Updater
-
-
Element
-
Filter
-
Form
-
Lists
-
Navigation
- ElementBase
- ElementHolder
-
-
Events
-
Exception
-
Extension
-
Filesystem
-
Flash
-
Foundation
-
Bootstrap
-
Console
-
Exception
-
Http
-
Middleware
- Kernel
-
-
Providers
- Application
-
-
Halcyon
-
Concerns
-
Datasource
-
Exception
-
Processors
-
Traits
- README
- Builder
- Collection
- HalcyonServiceProvider
- Model
-
-
Html
-
Mail
-
Network
-
Parse
-
Resize
-
Router
-
Scaffold
-
Support
-
Debug
-
Facades
-
Traits
- README
- Arr
- ClassLoader
- Collection
- Facade
- ModuleServiceProvider
- SafeCollection
- ServiceProvider
- Singleton
- Str
-
-
Translation
-
Validation
-
- Documentation
- API
- Library
- Database
- Concerns
- HasRelationships
October\Rain\Database\Concerns\HasRelationships
Overview
HasRelationships is a concern used by the \October\Rain\Database\Model class, employing a cleaner declaration of model relationships.
The relation definitions uses an almost identical approach to the relation methods defined by Eloquent, instead using class properties to make the class file less cluttered and keep the logic separated from the definition.
Relations should be declared with keys as the relation name and value as a mixed array.
The relation type $morphTo
does not include a class name as the first value.
Example:
class Order extends Model { protected $hasMany = [ 'items' => Item::class ]; }
Public Properties
public array $hasOne
hasOne related record, inverse of belongsTo.
protected $hasOne = [ 'owner' => [User::class, 'key' => 'user_id'] ];
public array $hasMany
hasMany related records, inverse of belongsTo.
protected $hasMany = [ 'items' => Item::class ];
public array $belongsTo
belongsTo another record with a local key attribute
protected $belongsTo = [ 'parent' => [Category::class, 'key' => 'parent_id'] ];
public array $belongsToMany
belongsToMany to multiple records using a join table.
protected $belongsToMany = [ 'groups' => [Group::class, 'table'=> 'join_groups_users'] ];
public array $morphTo
morphTo another record using local key and type attributes
protected $morphTo = [ 'pictures' => [] ];
public array $morphOne
morphOne related record, inverse of morphTo.
protected $morphOne = [ 'log' => [History::class, 'name' => 'user'] ];
public array $morphMany
morphMany related records, inverse of morphTo.
protected $morphMany = [ 'log' => [History::class, 'name' => 'user'] ];
public array $morphToMany
morphToMany to multiple records using a join table.
protected $morphToMany = [ 'tag' => [Tag::class, 'table' => 'tagables', 'name' => 'tagable'] ];
public array $morphedByMany
morphedByMany to a polymorphic, inverse many-to-many relationship.
public $morphedByMany = [ 'tag' => [Tag::class, 'table' => 'tagables', 'name' => 'tagable'] ];
public array $attachOne
attachOne file attachment.
protected $attachOne = [ 'picture' => [\October\Rain\Database\Attach\File::class, 'public' => false] ];
public array $attachMany
attachMany file attachments.
protected $attachMany = [ 'pictures' => [\October\Rain\Database\Attach\File::class, 'name'=> 'imageable'] ];
public array $hasManyThrough
hasManyThrough is related records through another record.
protected $hasManyThrough = [ 'posts' => [Post::class, 'through' => User::class] ];
public array $hasOneThrough
hasOneThrough is a related record through another record.
protected $hasOneThrough = [ 'post' => [Post::class, 'through' => User::class] ];
Protected Properties
protected static array $relationTypes
relationTypes expected, used to cycle and verify relationships.
Public Methods
public attachMany()
public attachMany( $related, $isPublic = null, $localKey = null, $relationName = null ): October\Rain\Database\Relations\MorphMany
attachMany defines an attachment one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public attachOne()
public attachOne( $related, $isPublic = true, $localKey = null, $relationName = null ): October\Rain\Database\Relations\MorphOne
attachOne defines an attachment one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public belongsTo()
public belongsTo( $related, $foreignKey = null, $parentKey = null, $relationName = null ): October\Rain\Database\Relations\BelongsTo
belongsTo defines an inverse one-to-one or many relationship. Overridden from \Eloquent\Model to allow the usage of the intermediary methods to handle the relationsData array.
public belongsToMany()
public belongsToMany( $related, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, $relationName = null ): October\Rain\Database\Relations\BelongsToMany
belongsToMany defines a many-to-many relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
public getRelationDefinition()
public getRelationDefinition($name): array
getRelationDefinition returns relationship details from a supplied name
public getRelationDefinitions()
public getRelationDefinitions(): array
getRelationDefinitions returns relationship details for all relations defined on this model
public getRelationSimpleValue()
public getRelationSimpleValue($relationName): void
getRelationSimpleValue returns a relation key value(s), not as an object.
public getRelationType()
public getRelationType(string $name): October\Rain\Database\Relation
getRelationType returns a relationship type based on a supplied name
public hasMany()
public hasMany( $related, $primaryKey = null, $localKey = null, $relationName = null ): October\Rain\Database\Relations\HasMany
hasMany defines a one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public hasManyThrough()
public hasManyThrough( $related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null ): October\Rain\Database\Relations\HasManyThrough
hasManyThrough defines a has-many-through relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public hasOne()
public hasOne( $related, $primaryKey = null, $localKey = null, $relationName = null ): October\Rain\Database\Relations\HasOne
hasOne defines a one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public hasOneThrough()
public hasOneThrough( $related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null ): October\Rain\Database\Relations\HasOneThrough
hasOneThrough define a has-one-through relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public hasRelation()
public hasRelation($name): bool
hasRelation checks if model has a relationship by supplied name
public isRelationPushable()
public isRelationPushable($name): bool
isRelationPushable determines whether the specified relation should be saved
when push()
is called instead of save()
on the model. Defaults to true
.
public isRelationTypeSingular()
public isRelationTypeSingular($name): bool
isRelationTypeSingular returns true if the relation is expected to return a single record versus a collection of records.
public makeRelation()
public makeRelation(string $name): Model|null
makeRelation returns a relation class object, supporting nested relations with dot notation
public morphMany()
public morphMany( $related, $name, $type = null, $id = null, $localKey = null, $relationName = null ): October\Rain\Database\Relations\MorphMany
morphMany defines a polymorphic one-to-many relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public morphOne()
public morphOne( $related, $name, $type = null, $id = null, $localKey = null, $relationName = null ): October\Rain\Database\Relations\MorphOne
morphOne defines a polymorphic one-to-one relationship. This code is a duplicate of Eloquent but uses a Rain relation class.
public morphTo()
public morphTo( $name = null, $type = null, $id = null, $ownerKey = null ): October\Rain\Database\Relations\BelongsTo
morphTo defines a polymorphic, inverse one-to-one or many relationship. Overridden from \Eloquent\Model to allow the usage of the intermediary methods to handle the relation.
public morphToMany()
public morphToMany( $related, $name, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, $inverse = false, $relationName = null ): October\Rain\Database\Relations\MorphToMany
morphToMany defines a polymorphic many-to-many relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
public morphedByMany()
public morphedByMany( $related, $name, $table = null, $primaryKey = null, $foreignKey = null, $parentKey = null, $relatedKey = null, $relationName = null ): October\Rain\Database\Relations\MorphToMany
morphedByMany defines a polymorphic many-to-many inverse relationship. This code is almost a duplicate of Eloquent but uses a Rain relation class.
Protected Methods
protected getRelationCaller()
protected getRelationCaller(): void
getRelationCaller finds the calling function name from the stack trace.
protected getRelationCustomClass()
protected getRelationCustomClass($name): string|null
getRelationCustomClass returns a custom relation class name for the relation or null if none is found.
protected getRelationDefaults()
protected getRelationDefaults(string $type): array
getRelationDefaults returns default relation arguments for a given type.
protected handleRelation()
protected handleRelation( string $relationName ): Illuminate\Database\Eloquent\Relations\Relation
handleRelation 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.
protected makeRelationInternal()
protected makeRelationInternal($relationName, $relationClass): void
makeRelationInternal is used internally to create a new related instance. It also
fires the afterRelation
to extend the created instance.
protected morphEagerTo()
protected morphEagerTo( string $name, string $type, string $id, string $ownerKey ): Illuminate\Database\Eloquent\Relations\MorphTo
morphEagerTo defines a polymorphic, inverse one-to-one or many relationship.
protected morphInstanceTo()
protected morphInstanceTo( string $target, string $name, string $type, string $id, string $ownerKey ): Illuminate\Database\Eloquent\Relations\MorphTo
morphInstanceTo defines a polymorphic, inverse one-to-one or many relationship
protected performDeleteOnRelations()
protected performDeleteOnRelations(): void
performDeleteOnRelations locates relations with delete flag and cascades the delete event. This is called before the parent model is deleted. This method checks in with the Multisite trait to preserve shared relations.
See Also
protected setRelationSimpleValue()
protected setRelationSimpleValue($relationName, $value): void
setRelationSimpleValue sets a relation value directly from its attribute.
protected validateRelationArgs()
protected validateRelationArgs($relationName, $optional, $required = []): void
validateRelationArgs supplied relation arguments