Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
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
sinan
laravel-mongodb
Commits
c110d762
Commit
c110d762
authored
Nov 27, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small BelongsToMany tweak
parent
040b7944
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
37 deletions
+38
-37
Model.php
src/Jenssegers/Mongodb/Model.php
+38
-37
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
c110d762
...
@@ -200,42 +200,43 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -200,42 +200,43 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
return
new
BelongsTo
(
$query
,
$this
,
$foreignKey
,
$otherKey
,
$relation
);
return
new
BelongsTo
(
$query
,
$this
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
/**
/**
* Define a many-to-many relationship.
* Define a many-to-many relationship.
*
*
* @param string $related
* @param string $related
* @param string $table
* @param string $table
* @param string $foreignKey
* @param string $foreignKey
* @param string $otherKey
* @param string $otherKey
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
*/
public
function
belongsToMany
(
$related
,
$collection
=
null
,
$foreignKey
=
null
,
$otherKey
=
null
)
public
function
belongsToMany
(
$related
,
$collection
=
null
,
$foreignKey
=
null
,
$otherKey
=
null
)
{
{
$caller
=
$this
->
getBelongsToManyCaller
();
$caller
=
$this
->
getBelongsToManyCaller
();
// First, we'll need to determine the foreign key and "other key" for the
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
// instances as well as the relationship instances we need for this.
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
()
.
's'
;
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
()
.
's'
;
$instance
=
new
$related
;
$instance
=
new
$related
;
$otherKey
=
$otherKey
?:
$instance
->
getForeignKey
()
.
's'
;
$otherKey
=
$otherKey
?:
$instance
->
getForeignKey
()
.
's'
;
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// If no table name was provided, we can guess it by concatenating the two
// are transformed to snake case from their default CamelCase also.
// models using underscores in alphabetical order. The two model names
if
(
is_null
(
$collection
))
// are transformed to snake case from their default CamelCase also.
{
if
(
is_null
(
$collection
))
$collection
=
snake_case
(
str_plural
(
class_basename
(
$related
)));
{
}
$collection
=
$instance
->
getTable
();
}
// Now we're ready to create a new query builder for the related model and
// the relationship instances for the relation. The relations will set
// Now we're ready to create a new query builder for the related model and
// appropriate query constraint and entirely manages the hydrations.
// the relationship instances for the relation. The relations will set
$query
=
$instance
->
newQuery
();
// appropriate query constraint and entirely manages the hydrations.
$query
=
$instance
->
newQuery
();
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$caller
[
'function'
]);
}
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$caller
[
'function'
]);
}
/**
/**
* Get a new query builder instance for the connection.
* Get a new query builder instance for the connection.
...
@@ -312,4 +313,4 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -312,4 +313,4 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
}
}
}
}
\ No newline at end of file
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