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
743cf6f4
Commit
743cf6f4
authored
Jul 08, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring DB\Eloquent.
parent
e6e7586d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
16 deletions
+21
-16
eloquent.php
system/db/eloquent.php
+21
-16
No files found.
system/db/eloquent.php
View file @
743cf6f4
...
...
@@ -116,7 +116,7 @@ abstract class Eloquent {
{
$model
=
new
$class
;
// Since this method is only used for instantiating
/
models for querying
// Since this method is only used for instantiating models for querying
// purposes, we will go ahead and set the Query instance on the model.
$model
->
query
=
Query
::
table
(
static
::
table
(
$class
));
...
...
@@ -132,6 +132,7 @@ abstract class Eloquent {
public
static
function
with
()
{
$model
=
static
::
make
(
get_called_class
());
$model
->
includes
=
func_get_args
();
return
$model
;
...
...
@@ -197,15 +198,16 @@ abstract class Eloquent {
/**
* Retrieve the query for a 1:1 or 1:* relationship.
*
* The default foreign key for has one and has many relationships is the name
* of the model with an appended _id. For example, the foreign key for a
* User model would be user_id. Photo would be photo_id, etc.
*
* @param string $model
* @param string $foreign_key
* @return mixed
*/
private
function
has_one_or_many
(
$model
,
$foreign_key
)
{
// The default foreign key for has one and has many relationships is the name
// of the model with an appended _id. For example, the foreign key for a
// User model would be user_id. Photo would be photo_id, etc.
$this
->
relating_key
=
(
is_null
(
$foreign_key
))
?
strtolower
(
get_class
(
$this
))
.
'_id'
:
$foreign_key
;
return
static
::
make
(
$model
)
->
where
(
$this
->
relating_key
,
'='
,
$this
->
id
);
...
...
@@ -214,6 +216,10 @@ abstract class Eloquent {
/**
* Retrieve the query for a 1:1 belonging relationship.
*
* The default foreign key for belonging relationships is the name of the
* relationship method name with _id. So, if a model has a "manager" method
* returning a belongs_to relationship, the key would be manager_id.
*
* @param string $model
* @param string $foreign_key
* @return mixed
...
...
@@ -228,9 +234,6 @@ abstract class Eloquent {
}
else
{
// The default foreign key for belonging relationships is the name of the
// relationship method name with _id. So, if a model has a "manager" method
// returning a belongs_to relationship, the key would be manager_id.
list
(,
$caller
)
=
debug_backtrace
(
false
);
$this
->
relating_key
=
$caller
[
'function'
]
.
'_id'
;
...
...
@@ -242,6 +245,12 @@ abstract class Eloquent {
/**
* Retrieve the query for a *:* relationship.
*
* By default, the intermediate table name is the plural names of the models
* arranged alphabetically and concatenated with an underscore.
*
* The default foreign key for many-to-many relations is the name of the model
* with an appended _id. This is the same convention as has_one and has_many.
*
* @param string $model
* @param string $table
* @return mixed
...
...
@@ -250,23 +259,19 @@ abstract class Eloquent {
{
$this
->
relating
=
__FUNCTION__
;
if
(
!
is_null
(
$table
))
if
(
is_null
(
$table
))
{
$this
->
relating_table
=
$table
;
}
else
{
// By default, the intermediate table name is the plural names of the models
// arranged alphabetically and concatenated with an underscore.
$models
=
array
(
Inflector
::
plural
(
$model
),
Inflector
::
plural
(
get_class
(
$this
)));
sort
(
$models
);
$this
->
relating_table
=
strtolower
(
$models
[
0
]
.
'_'
.
$models
[
1
]);
}
else
{
$this
->
relating_table
=
$table
;
}
// The default foreign key for many-to-many relations is the name of the model with an appended _id.
// This is the same convention as has_one and has_many.
$this
->
relating_key
=
strtolower
(
get_class
(
$this
))
.
'_id'
;
return
static
::
make
(
$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