Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
079400ff
Commit
079400ff
authored
Mar 20, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow passing in a model instance to relationship insert / update methods.
parent
e540fd3b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
belongs_to.php
laravel/database/eloquent/relationships/belongs_to.php
+3
-1
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+11
-6
has_one_or_many.php
laravel/database/eloquent/relationships/has_one_or_many.php
+3
-1
No files found.
laravel/database/eloquent/relationships/belongs_to.php
View file @
079400ff
...
...
@@ -15,11 +15,13 @@ class Belongs_To extends Relationship {
/**
* Update the parent model of the relationship.
*
* @param array $attributes
* @param
Model|
array $attributes
* @return int
*/
public
function
update
(
$attributes
)
{
$attributes
=
(
$attributes
instanceof
Model
)
?
$attributes
->
get_dirty
()
:
$attributes
;
return
$this
->
model
->
update
(
$this
->
foreign_value
(),
$attributes
);
}
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
079400ff
...
...
@@ -79,7 +79,7 @@ class Has_Many_And_Belongs_To extends Relationship {
* @param array $joining
* @return bool
*/
public
function
a
dd
(
$id
,
$attributes
=
array
())
public
function
a
ttach
(
$id
,
$attributes
=
array
())
{
$joining
=
array_merge
(
$this
->
join_record
(
$id
),
$attributes
);
...
...
@@ -89,12 +89,20 @@ class Has_Many_And_Belongs_To extends Relationship {
/**
* Insert a new record for the association.
*
* @param array $attributes
* @param
Model|
array $attributes
* @param array $joining
* @return bool
*/
public
function
insert
(
$attributes
,
$joining
=
array
())
{
// If the attributes are actually an instance of a model, we'll just grab the
// array of attributes off of the model for saving, allowing the developer
// to easily validate the joining models before inserting them.
if
(
$attributes
instanceof
Model
)
{
$attributes
=
$attributes
->
attributes
;
}
$model
=
$this
->
model
->
create
(
$attributes
);
// If the insert was successful, we'll insert a record into the joining table
...
...
@@ -139,9 +147,6 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
protected
function
insert_joining
(
$attributes
)
{
// All joining tables get creation and update timestamps automatically even though
// some developers may not need them. This just provides them if necessary since
// it would be a pain for the developer to maintain them each manually.
$attributes
[
'created_at'
]
=
$this
->
model
->
get_timestamp
();
$attributes
[
'updated_at'
]
=
$attributes
[
'created_at'
];
...
...
laravel/database/eloquent/relationships/has_one_or_many.php
View file @
079400ff
...
...
@@ -7,11 +7,13 @@ class Has_One_Or_Many extends Relationship {
/**
* Insert a new record for the association.
*
* @param array $attributes
* @param
Model|
array $attributes
* @return bool
*/
public
function
insert
(
$attributes
)
{
$attributes
=
(
$attributes
instanceof
Model
)
?
$attributes
->
attributes
:
$attributes
;
$attributes
[
$this
->
foreign_key
()]
=
$this
->
base
->
get_key
();
return
$this
->
model
->
create
(
$attributes
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment