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
c6c164dc
Commit
c6c164dc
authored
Sep 25, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made link() and unlink() compatible with NoSQL AR
parent
3e75c117
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
79 deletions
+31
-79
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+25
-4
ActiveRecord.php
framework/yii/redis/ActiveRecord.php
+6
-75
No files found.
framework/yii/db/ActiveRecord.php
View file @
c6c164dc
...
@@ -1310,9 +1310,7 @@ class ActiveRecord extends Model
...
@@ -1310,9 +1310,7 @@ class ActiveRecord extends Model
if
(
is_array
(
$relation
->
via
))
{
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaRelation ActiveRelation */
/** @var $viaRelation ActiveRelation */
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
/** @var $viaClass ActiveRecord */
$viaClass
=
$viaRelation
->
modelClass
;
$viaClass
=
$viaRelation
->
modelClass
;
$viaTable
=
$viaClass
::
tableName
();
// unset $viaName so that it can be reloaded to reflect the change
// unset $viaName so that it can be reloaded to reflect the change
unset
(
$this
->
_related
[
strtolower
(
$viaName
)]);
unset
(
$this
->
_related
[
strtolower
(
$viaName
)]);
}
else
{
}
else
{
...
@@ -1329,8 +1327,19 @@ class ActiveRecord extends Model
...
@@ -1329,8 +1327,19 @@ class ActiveRecord extends Model
foreach
(
$extraColumns
as
$k
=>
$v
)
{
foreach
(
$extraColumns
as
$k
=>
$v
)
{
$columns
[
$k
]
=
$v
;
$columns
[
$k
]
=
$v
;
}
}
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaClass ActiveRecord */
/** @var $record ActiveRecord */
$record
=
new
$viaClass
();
foreach
(
$columns
as
$column
=>
$value
)
{
$record
->
$column
=
$value
;
}
$record
->
insert
(
false
);
}
else
{
/** @var $viaTable string */
static
::
getDb
()
->
createCommand
()
static
::
getDb
()
->
createCommand
()
->
insert
(
$viaTable
,
$columns
)
->
execute
();
->
insert
(
$viaTable
,
$columns
)
->
execute
();
}
}
else
{
}
else
{
$p1
=
$model
->
isPrimaryKey
(
array_keys
(
$relation
->
link
));
$p1
=
$model
->
isPrimaryKey
(
array_keys
(
$relation
->
link
));
$p2
=
$this
->
isPrimaryKey
(
array_values
(
$relation
->
link
));
$p2
=
$this
->
isPrimaryKey
(
array_values
(
$relation
->
link
));
...
@@ -1385,9 +1394,7 @@ class ActiveRecord extends Model
...
@@ -1385,9 +1394,7 @@ class ActiveRecord extends Model
if
(
is_array
(
$relation
->
via
))
{
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaRelation ActiveRelation */
/** @var $viaRelation ActiveRelation */
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
/** @var $viaClass ActiveRecord */
$viaClass
=
$viaRelation
->
modelClass
;
$viaClass
=
$viaRelation
->
modelClass
;
$viaTable
=
$viaClass
::
tableName
();
unset
(
$this
->
_related
[
strtolower
(
$viaName
)]);
unset
(
$this
->
_related
[
strtolower
(
$viaName
)]);
}
else
{
}
else
{
$viaRelation
=
$relation
->
via
;
$viaRelation
=
$relation
->
via
;
...
@@ -1400,6 +1407,19 @@ class ActiveRecord extends Model
...
@@ -1400,6 +1407,19 @@ class ActiveRecord extends Model
foreach
(
$relation
->
link
as
$a
=>
$b
)
{
foreach
(
$relation
->
link
as
$a
=>
$b
)
{
$columns
[
$b
]
=
$model
->
$a
;
$columns
[
$b
]
=
$model
->
$a
;
}
}
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaClass ActiveRecord */
if
(
$delete
)
{
$viaClass
::
deleteAll
(
$columns
);
}
else
{
$nulls
=
array
();
foreach
(
array_keys
(
$columns
)
as
$a
)
{
$nulls
[
$a
]
=
null
;
}
$viaClass
::
updateAll
(
$nulls
,
$columns
);
}
}
else
{
/** @var $viaTable string */
$command
=
static
::
getDb
()
->
createCommand
();
$command
=
static
::
getDb
()
->
createCommand
();
if
(
$delete
)
{
if
(
$delete
)
{
$command
->
delete
(
$viaTable
,
$columns
)
->
execute
();
$command
->
delete
(
$viaTable
,
$columns
)
->
execute
();
...
@@ -1410,6 +1430,7 @@ class ActiveRecord extends Model
...
@@ -1410,6 +1430,7 @@ class ActiveRecord extends Model
}
}
$command
->
update
(
$viaTable
,
$nulls
,
$columns
)
->
execute
();
$command
->
update
(
$viaTable
,
$nulls
,
$columns
)
->
execute
();
}
}
}
}
else
{
}
else
{
$p1
=
$model
->
isPrimaryKey
(
array_keys
(
$relation
->
link
));
$p1
=
$model
->
isPrimaryKey
(
array_keys
(
$relation
->
link
));
$p2
=
$this
->
isPrimaryKey
(
array_values
(
$relation
->
link
));
$p2
=
$this
->
isPrimaryKey
(
array_values
(
$relation
->
link
));
...
...
framework/yii/redis/ActiveRecord.php
View file @
c6c164dc
...
@@ -367,83 +367,14 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
...
@@ -367,83 +367,14 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
return
false
;
return
false
;
}
}
// TODO port these changes back to AR
/**
/**
* @inheritDocs
* Returns a value indicating whether the specified operation is transactional in the current [[scenario]].
*/
* This method will always return false as transactional operations are not supported by redis.
public
function
link
(
$name
,
$model
,
$extraColumns
=
array
())
* @param integer $operation the operation to check. Possible values are [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]].
{
* @return boolean whether the specified operation is transactional in the current [[scenario]].
$relation
=
$this
->
getRelation
(
$name
);
if
(
$relation
->
via
!==
null
)
{
if
(
$this
->
getIsNewRecord
()
||
$model
->
getIsNewRecord
())
{
throw
new
InvalidCallException
(
'Unable to link models: both models must NOT be newly created.'
);
}
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaRelation ActiveRelation */
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
/** @var $viaClass ActiveRecord */
$viaClass
=
$viaRelation
->
modelClass
;
// unset $viaName so that it can be reloaded to reflect the change
// unset($this->_related[strtolower($viaName)]); // TODO this needs private access
}
else
{
throw
new
NotSupportedException
(
'redis does not support relations via table.'
);
}
$columns
=
array
();
foreach
(
$viaRelation
->
link
as
$a
=>
$b
)
{
$columns
[
$a
]
=
$this
->
$b
;
}
foreach
(
$relation
->
link
as
$a
=>
$b
)
{
$columns
[
$b
]
=
$model
->
$a
;
}
foreach
(
$extraColumns
as
$k
=>
$v
)
{
$columns
[
$k
]
=
$v
;
}
$record
=
new
$viaClass
();
foreach
(
$columns
as
$column
=>
$value
)
{
$record
->
$column
=
$value
;
}
$record
->
insert
();
}
else
{
parent
::
link
(
$name
,
$model
,
$extraColumns
);
}
}
/**
* @inheritDocs
*/
*/
public
function
unlink
(
$name
,
$model
,
$delete
=
false
)
public
function
isTransactional
(
$operation
)
{
{
$relation
=
$this
->
getRelation
(
$name
);
return
false
;
if
(
$relation
->
via
!==
null
)
{
if
(
is_array
(
$relation
->
via
))
{
/** @var $viaRelation ActiveRelation */
list
(
$viaName
,
$viaRelation
)
=
$relation
->
via
;
/** @var $viaClass ActiveRecord */
$viaClass
=
$viaRelation
->
modelClass
;
//unset($this->_related[strtolower($viaName)]); // TODO this needs private access
}
else
{
throw
new
NotSupportedException
(
'redis does not support relations via table.'
);
}
$columns
=
array
();
foreach
(
$viaRelation
->
link
as
$a
=>
$b
)
{
$columns
[
$a
]
=
$this
->
$b
;
}
foreach
(
$relation
->
link
as
$a
=>
$b
)
{
$columns
[
$b
]
=
$model
->
$a
;
}
if
(
$delete
)
{
$viaClass
::
deleteAll
(
$columns
);
}
else
{
$nulls
=
array
();
foreach
(
array_keys
(
$columns
)
as
$a
)
{
$nulls
[
$a
]
=
null
;
}
$viaClass
::
updateAll
(
$nulls
,
$columns
);
}
}
else
{
parent
::
unlink
(
$name
,
$model
,
$delete
);
}
}
}
}
}
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