Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
cf6c73c6
Commit
cf6c73c6
authored
Jan 12, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
link relation WIP
parent
ef8b0922
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
+36
-3
ActiveRecord.php
framework/db/ActiveRecord.php
+36
-3
No files found.
framework/db/ActiveRecord.php
View file @
cf6c73c6
...
@@ -873,6 +873,8 @@ abstract class ActiveRecord extends Model
...
@@ -873,6 +873,8 @@ abstract class ActiveRecord extends Model
/** @var $viaClass ActiveRecord */
/** @var $viaClass ActiveRecord */
$viaClass
=
$viaQuery
->
modelClass
;
$viaClass
=
$viaQuery
->
modelClass
;
$viaTable
=
$viaClass
::
tableName
();
$viaTable
=
$viaClass
::
tableName
();
// unset $viaName so that it can be reloaded to reflect the change
unset
(
$this
->
_related
[
$viaName
]);
}
else
{
}
else
{
$viaQuery
=
$relation
->
via
;
$viaQuery
=
$relation
->
via
;
$viaTable
=
reset
(
$relation
->
via
->
from
);
$viaTable
=
reset
(
$relation
->
via
->
from
);
...
@@ -889,8 +891,18 @@ abstract class ActiveRecord extends Model
...
@@ -889,8 +891,18 @@ abstract class ActiveRecord extends Model
}
}
$command
=
$this
->
getDbConnection
()
->
createCommand
();
$command
=
$this
->
getDbConnection
()
->
createCommand
();
$command
->
insert
(
$viaTable
,
$columns
)
->
execute
();
$command
->
insert
(
$viaTable
,
$columns
)
->
execute
();
$name
=
strtolower
(
$name
);
if
(
!
$relation
->
multiple
)
{
$this
->
_related
[
$name
]
=
$model
;
}
elseif
(
isset
(
$this
->
_related
[
$name
]))
{
if
(
$relation
->
indexBy
!==
null
)
{
$indexBy
=
$relation
->
indexBy
;
$this
->
_related
[
$name
][
$model
->
$indexBy
]
=
$model
;
}
else
{
$this
->
_related
[
$name
][]
=
$model
;
}
}
return
;
return
;
// todo: update $viaName
}
}
$keys
=
$model
->
primaryKey
();
$keys
=
$model
->
primaryKey
();
$p1
=
true
;
$p1
=
true
;
...
@@ -953,7 +965,18 @@ abstract class ActiveRecord extends Model
...
@@ -953,7 +965,18 @@ abstract class ActiveRecord extends Model
}
else
{
}
else
{
throw
new
Exception
(
''
);
throw
new
Exception
(
''
);
}
}
// todo: update relation models
if
(
!
$relation
->
multiple
)
{
$this
->
_related
[
$name
]
=
$model
;
}
elseif
(
isset
(
$this
->
_related
[
$name
]))
{
if
(
$relation
->
indexBy
!==
null
)
{
$indexBy
=
$relation
->
indexBy
;
$this
->
_related
[
$name
][
$model
->
$indexBy
]
=
$model
;
}
else
{
$this
->
_related
[
$name
][]
=
$model
;
}
}
return
;
}
}
/**
/**
...
@@ -1022,7 +1045,17 @@ abstract class ActiveRecord extends Model
...
@@ -1022,7 +1045,17 @@ abstract class ActiveRecord extends Model
}
else
{
}
else
{
throw
new
Exception
(
''
);
throw
new
Exception
(
''
);
}
}
// todo: update relation models
if
(
!
$relation
->
multiple
)
{
unset
(
$this
->
_related
[
$name
]);
}
elseif
(
isset
(
$this
->
_related
[
$name
]))
{
/** @var $b ActiveRecord */
foreach
(
$this
->
_related
[
$name
]
as
$a
=>
$b
)
{
if
(
$model
->
getPrimaryKey
()
==
$b
->
getPrimaryKey
())
{
unset
(
$this
->
_related
[
$name
][
$a
]);
}
}
}
}
}
/**
/**
...
...
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