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
666ebf21
Commit
666ebf21
authored
Jul 08, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Eloquent class.
parent
743cf6f4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
23 deletions
+42
-23
eloquent.php
system/db/eloquent.php
+42
-23
No files found.
system/db/eloquent.php
View file @
666ebf21
...
...
@@ -295,35 +295,41 @@ abstract class Eloquent {
$model
=
get_class
(
$this
);
// Since the model was instantiated using "new", a query instance has not been set.
// Only models being used for querying have their query instances set by default.
$this
->
query
=
Query
::
table
(
static
::
table
(
$model
));
// Set the creation and update timestamps.
if
(
property_exists
(
$model
,
'timestamps'
)
and
$model
::
$timestamps
)
{
$this
->
updated_at
=
date
(
'Y-m-d H:i:s'
);
if
(
!
$this
->
exists
)
{
$this
->
created_at
=
$this
->
updated_at
;
$this
->
timestamp
();
}
$result
=
(
$this
->
exists
)
?
$this
->
update
()
:
$this
->
insert
();
$this
->
dirty
=
array
();
return
$result
;
}
// If the model already exists in the database, we only need to update it.
// Otherwise, we'll insert the model into the database.
if
(
$this
->
exists
)
/**
* Update an existing model in the database.
*
* @return bool
*/
private
function
update
()
{
$result
=
$this
->
query
->
where
(
'id'
,
'='
,
$this
->
attributes
[
'id'
])
->
update
(
$this
->
dirty
)
==
1
;
return
$this
->
query
->
where
(
'id'
,
'='
,
$this
->
attributes
[
'id'
])
->
update
(
$this
->
dirty
)
==
1
;
}
else
/**
* Insert a new model into the database.
*
* @return bool
*/
private
function
insert
()
{
$this
->
attributes
[
'id'
]
=
$this
->
query
->
insert_get_id
(
$this
->
attributes
);
$result
=
$this
->
exists
=
is_numeric
(
$this
->
id
);
}
$this
->
dirty
=
array
();
return
$result
;
return
$this
->
exists
=
is_numeric
(
$this
->
id
);
}
/**
...
...
@@ -342,20 +348,33 @@ abstract class Eloquent {
return
0
;
}
/**
* Set the creation and update timestamps on the model.
*
* @return void
*/
private
function
timestamp
()
{
$this
->
updated_at
=
date
(
'Y-m-d H:i:s'
);
if
(
!
$this
->
exists
)
{
$this
->
created_at
=
$this
->
updated_at
;
}
}
/**
* Magic method for retrieving model attributes.
*/
public
function
__get
(
$key
)
{
// Check the ignored attributes first. These attributes hold all of the
// loaded relationships for the model.
// The ignored attributes hold all of the loaded relationships for the model.
if
(
array_key_exists
(
$key
,
$this
->
ignore
))
{
return
$this
->
ignore
[
$key
];
}
// Is the attribute actually a relationship method? If it is, return the
// models for the relationship.
// If the attribute is a relationship method, return the related models.
if
(
method_exists
(
$this
,
$key
))
{
$model
=
$this
->
$key
();
...
...
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