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
fcff36a0
Commit
fcff36a0
authored
Mar 18, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added related model updating from belongs_to relationship.
parent
68b4e553
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
5 deletions
+42
-5
model.php
laravel/database/eloquent/model.php
+16
-0
belongs_to.php
laravel/database/eloquent/relationships/belongs_to.php
+22
-3
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+3
-1
relationship.php
laravel/database/eloquent/relationships/relationship.php
+1
-1
No files found.
laravel/database/eloquent/model.php
View file @
fcff36a0
...
...
@@ -174,6 +174,22 @@ abstract class Model {
return
(
$success
)
?
$model
:
false
;
}
/**
* Update a model instance in the database.
*
* @param mixed $id
* @param array $attributes
* @return int
*/
public
static
function
update
(
$id
,
$attributes
)
{
$model
=
new
static
(
array
(),
true
);
if
(
static
::
$timestamps
)
$attributes
[
'updated_at'
]
=
$model
->
get_timestamp
();
return
$model
->
query
()
->
where
(
$model
->
key
(),
'='
,
$id
)
->
update
(
$attributes
);
}
/**
* Find a model by its primary key.
*
...
...
laravel/database/eloquent/relationships/belongs_to.php
View file @
fcff36a0
...
...
@@ -12,6 +12,17 @@ class Belongs_To extends Relationship {
return
parent
::
first
();
}
/**
* Update the parent model of the relationship.
*
* @param array $attributes
* @return int
*/
public
function
update
(
$attributes
)
{
return
$this
->
model
->
update
(
$this
->
foreign_value
(),
$attributes
);
}
/**
* Set the proper constraints on the relationship table.
*
...
...
@@ -19,9 +30,7 @@ class Belongs_To extends Relationship {
*/
protected
function
constrain
()
{
$foreign
=
$this
->
base
->
get_attribute
(
$this
->
foreign
);
$this
->
table
->
where
(
$this
->
base
->
key
(),
'='
,
$foreign
);
$this
->
table
->
where
(
$this
->
base
->
key
(),
'='
,
$this
->
foreign_value
());
}
/**
...
...
@@ -80,4 +89,14 @@ class Belongs_To extends Relationship {
}
}
/**
* Get the value of the foreign key from the base model.
*
* @return mixed
*/
public
function
foreign_value
()
{
return
$this
->
base
->
get_attribute
(
$this
->
foreign
);
}
}
\ No newline at end of file
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
fcff36a0
...
...
@@ -114,7 +114,9 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
public
function
delete
()
{
return
$this
->
joining_table
()
->
where
(
$this
->
foreign_key
(),
'='
,
$this
->
base
->
get_key
())
->
delete
();
$id
=
$this
->
base
->
get_key
();
return
$this
->
joining_table
()
->
where
(
$this
->
foreign_key
(),
'='
,
$id
)
->
delete
();
}
/**
...
...
laravel/database/eloquent/relationships/relationship.php
View file @
fcff36a0
...
...
@@ -57,7 +57,7 @@ abstract class Relationship extends Query {
{
if
(
!
is_null
(
$foreign
))
return
$foreign
;
// If the model is an object
, we wi
ll simply get the class of the object and
// If the model is an object
we'
ll simply get the class of the object and
// then take the basename, which is simply the object name minus the
// namespace, and we'll append "_id" to the name.
if
(
is_object
(
$model
))
...
...
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