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
c9c0ddf5
Commit
c9c0ddf5
authored
Mar 16, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing bugs in Eq2.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
e857505e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
9 deletions
+36
-9
model.php
laravel/database/eloquent/model.php
+4
-4
query.php
laravel/database/eloquent/query.php
+9
-1
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+16
-2
has_one_or_many.php
laravel/database/eloquent/relationships/has_one_or_many.php
+3
-1
relationship.php
laravel/database/eloquent/relationships/relationship.php
+4
-1
No files found.
laravel/database/eloquent/model.php
View file @
c9c0ddf5
<?php
namespace
Laravel\Database\Eloquent
;
<?php
namespace
Laravel\Database\Eloquent
;
use
Laravel\Database
;
use
Laravel\Database
;
use
Eloquent\Relationships\Has_Many_And_Belongs_To
;
use
Laravel\Database\
Eloquent\Relationships\Has_Many_And_Belongs_To
;
abstract
class
Model
{
abstract
class
Model
{
...
@@ -320,7 +320,7 @@ abstract class Model {
...
@@ -320,7 +320,7 @@ abstract class Model {
*/
*/
protected
function
timestamp
()
protected
function
timestamp
()
{
{
$this
->
updated_at
=
$this
->
get_timestamp
();
$this
->
updated_at
=
static
::
get_timestamp
();
if
(
!
$this
->
exists
)
$this
->
created_at
=
$this
->
updated_at
;
if
(
!
$this
->
exists
)
$this
->
created_at
=
$this
->
updated_at
;
}
}
...
@@ -330,7 +330,7 @@ abstract class Model {
...
@@ -330,7 +330,7 @@ abstract class Model {
*
*
* @return mixed
* @return mixed
*/
*/
protected
function
get_timestamp
()
protected
static
function
get_timestamp
()
{
{
return
date
(
'Y-m-d H:i:s'
);
return
date
(
'Y-m-d H:i:s'
);
}
}
...
@@ -406,7 +406,7 @@ abstract class Model {
...
@@ -406,7 +406,7 @@ abstract class Model {
*/
*/
public
function
get_attribute
(
$key
)
public
function
get_attribute
(
$key
)
{
{
return
$this
->
attributes
[
$key
]
;
return
array_get
(
$this
->
attributes
,
$key
)
;
}
}
/**
/**
...
...
laravel/database/eloquent/query.php
View file @
c9c0ddf5
...
@@ -76,7 +76,7 @@ class Query {
...
@@ -76,7 +76,7 @@ class Query {
{
{
// If the relationship is nested, we will skip laoding it here and let
// If the relationship is nested, we will skip laoding it here and let
// the load method parse and set the nested eager loads on the right
// the load method parse and set the nested eager loads on the right
// relationship when it is getting ready to eager laod
it
.
// relationship when it is getting ready to eager laod.
if
(
str_contains
(
$relationship
,
'.'
))
if
(
str_contains
(
$relationship
,
'.'
))
{
{
continue
;
continue
;
...
@@ -86,6 +86,14 @@ class Query {
...
@@ -86,6 +86,14 @@ class Query {
}
}
}
}
// The many to many relationships may have pivot table column on them
// so we will call the "clean" method on the relationship to remove
// any pivot columns that are on the model.
if
(
$this
instanceof
Relationships\Has_Many_And_Belongs_To
)
{
$this
->
clean
(
$results
);
}
return
$results
;
return
$results
;
}
}
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
c9c0ddf5
...
@@ -133,7 +133,7 @@ class Has_Many_And_Belongs_To extends Relationship {
...
@@ -133,7 +133,7 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
*/
protected
function
set_select
(
$foreign
)
protected
function
set_select
(
$foreign
)
{
{
$foreign
=
$this
->
joining
.
'.'
.
$foreign
.
' as
eloquen
t_foreign_key'
;
$foreign
=
$this
->
joining
.
'.'
.
$foreign
.
' as
pivo
t_foreign_key'
;
$this
->
table
->
select
(
array
(
$this
->
model
->
table
()
.
'.*'
,
$foreign
));
$this
->
table
->
select
(
array
(
$this
->
model
->
table
()
.
'.*'
,
$foreign
));
...
@@ -201,7 +201,7 @@ class Has_Many_And_Belongs_To extends Relationship {
...
@@ -201,7 +201,7 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
*/
public
function
match
(
$relationship
,
&
$parents
,
$children
)
public
function
match
(
$relationship
,
&
$parents
,
$children
)
{
{
$foreign
=
'
eloquen
t_foreign_key'
;
$foreign
=
'
pivo
t_foreign_key'
;
foreach
(
$children
as
$key
=>
$child
)
foreach
(
$children
as
$key
=>
$child
)
{
{
...
@@ -216,6 +216,20 @@ class Has_Many_And_Belongs_To extends Relationship {
...
@@ -216,6 +216,20 @@ class Has_Many_And_Belongs_To extends Relationship {
}
}
}
}
/**
* Clean-up any pivot columns that are on the results.
*
* @param array $results
* @return void
*/
protected
function
clean
(
&
$results
)
{
foreach
(
$results
as
&
$result
)
{
}
}
/**
/**
* Get the other or associated key for the relationship.
* Get the other or associated key for the relationship.
*
*
...
...
laravel/database/eloquent/relationships/has_one_or_many.php
View file @
c9c0ddf5
<?php
namespace
Laravel\Database\Eloquent\Relationships
;
use
Eloquent\Model
;
<?php
namespace
Laravel\Database\Eloquent\Relationships
;
use
Laravel\Database\Eloquent\Model
;
class
Has_One_Or_Many
extends
Relationship
{
class
Has_One_Or_Many
extends
Relationship
{
...
...
laravel/database/eloquent/relationships/relationship.php
View file @
c9c0ddf5
<?php
namespace
Laravel\Database\Eloquent\Relationships
;
use
Eloquent\Model
,
Eloquent\Query
;
<?php
namespace
Laravel\Database\Eloquent\Relationships
;
use
Laravel\Database\Eloquent\Model
;
use
Laravel\Database\Eloquent\Query
;
abstract
class
Relationship
extends
Query
{
abstract
class
Relationship
extends
Query
{
...
...
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