Page Menu
Home
WMGMC Issues
搜索
Configure Global Search
登录
Files
F16346
HasOne.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
订阅
标记用于日后
授予令牌
Size
1 KB
Referenced Files
None
订阅者
None
HasOne.php
View Options
<?php
namespace
LdapRecord\Models\Relations
;
use
LdapRecord\Models\Model
;
class
HasOne
extends
Relation
{
/**
* Get the results of the relationship.
*
* @return \LdapRecord\Query\Collection
*/
public
function
getResults
()
{
$model
=
$this
->
getForeignModelByValue
(
$this
->
getFirstAttributeValue
(
$this
->
parent
,
$this
->
relationKey
)
);
return
$this
->
transformResults
(
$this
->
parent
->
newCollection
(
$model
?
[
$model
]
:
null
)
);
}
/**
* Attach a model instance to the parent model.
*
* @param Model|string $model
* @return Model|string
*
* @throws \LdapRecord\LdapRecordException
*/
public
function
attach
(
$model
)
{
$foreign
=
$model
instanceof
Model
?
$this
->
getForeignValueFromModel
(
$model
)
:
$model
;
$this
->
parent
->
setAttribute
(
$this
->
relationKey
,
$foreign
)->
save
();
return
$model
;
}
/**
* Detach the related model from the parent.
*
* @return void
*
* @throws \LdapRecord\LdapRecordException
*/
public
function
detach
()
{
$this
->
parent
->
setAttribute
(
$this
->
relationKey
,
null
)->
save
();
}
}
File Metadata
详情
附加的
Mime Type
text/x-php
Expires
9月 12 Fri, 3:11 AM (20 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5791
默认替代文本
HasOne.php (1 KB)
Attached To
Mode
rMAILCOW mailcow-tracking
附加的
Detach File
Event Timeline
Log In to Comment