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
982a27db
Commit
982a27db
authored
Sep 23, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed support for unlinkAll() from elasticsearch
feature is not reliable fixes #5136
parent
3b0f5614
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
3 deletions
+53
-3
ActiveRecord.php
extensions/elasticsearch/ActiveRecord.php
+11
-0
CHANGELOG.md
extensions/elasticsearch/CHANGELOG.md
+0
-1
ActiveRecordTest.php
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
+42
-2
No files found.
extensions/elasticsearch/ActiveRecord.php
View file @
982a27db
...
@@ -10,6 +10,7 @@ namespace yii\elasticsearch;
...
@@ -10,6 +10,7 @@ namespace yii\elasticsearch;
use
Yii
;
use
Yii
;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidCallException
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\base\NotSupportedException
;
use
yii\db\BaseActiveRecord
;
use
yii\db\BaseActiveRecord
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Inflector
;
use
yii\helpers\Inflector
;
...
@@ -604,4 +605,14 @@ class ActiveRecord extends BaseActiveRecord
...
@@ -604,4 +605,14 @@ class ActiveRecord extends BaseActiveRecord
return
$n
;
return
$n
;
}
}
/**
* Destroys the relationship in current model.
*
* This method is not supported by elasticsearch.
*/
public
function
unlinkAll
(
$name
,
$delete
=
false
)
{
throw
new
NotSupportedException
(
'unlinkAll() is not supported by elasticsearch, use unlink() instead.'
);
}
}
}
extensions/elasticsearch/CHANGELOG.md
View file @
982a27db
...
@@ -6,7 +6,6 @@ Yii Framework 2 elasticsearch extension Change Log
...
@@ -6,7 +6,6 @@ Yii Framework 2 elasticsearch extension Change Log
-
Bug #3587: Fixed an issue with storing empty records (cebe)
-
Bug #3587: Fixed an issue with storing empty records (cebe)
-
Bug #4187: Elasticsearch dynamic scripting is disabled in 1.2.0, so do not use it in query builder (cebe)
-
Bug #4187: Elasticsearch dynamic scripting is disabled in 1.2.0, so do not use it in query builder (cebe)
-
Enh #3520: Added
`unlinkAll()`
-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
-
Enh #3527: Added
`highlight`
property to Query and ActiveRecord. (Borales)
-
Enh #3527: Added
`highlight`
property to Query and ActiveRecord. (Borales)
-
Enh #4048: Added
`init`
event to
`ActiveQuery`
classes (qiangxue)
-
Enh #4048: Added
`init`
event to
`ActiveQuery`
classes (qiangxue)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
...
...
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
View file @
982a27db
...
@@ -804,6 +804,9 @@ class ActiveRecordTest extends ElasticSearchTestCase
...
@@ -804,6 +804,9 @@ class ActiveRecordTest extends ElasticSearchTestCase
$this
->
assertFalse
(
isset
(
$items
[
2
]));
$this
->
assertFalse
(
isset
(
$items
[
2
]));
}
}
/**
* @expectedException \yii\base\NotSupportedException
*/
public
function
testArrayAttributeRelationUnLinkAll
()
public
function
testArrayAttributeRelationUnLinkAll
()
{
{
/* @var $order Order */
/* @var $order Order */
...
@@ -825,14 +828,51 @@ class ActiveRecordTest extends ElasticSearchTestCase
...
@@ -825,14 +828,51 @@ class ActiveRecordTest extends ElasticSearchTestCase
$this
->
assertEquals
(
0
,
count
(
$items
));
$this
->
assertEquals
(
0
,
count
(
$items
));
}
}
public
function
testUnlinkAll
()
{
// not supported by elasticsearch
}
/**
* @expectedException \yii\base\NotSupportedException
*/
public
function
testUnlinkAllAndConditionSetNull
()
public
function
testUnlinkAllAndConditionSetNull
()
{
{
$this
->
markTestSkipped
(
'https://github.com/yiisoft/yii2/issues/5136'
);
/* @var $customerClass \yii\db\BaseActiveRecord */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\BaseActiveRecord */
$orderClass
=
$this
->
getOrderWithNullFKClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
$this
->
assertEquals
(
3
,
$orderClass
::
find
()
->
count
());
$customer
->
unlinkAll
(
'expensiveOrdersWithNullFK'
);
}
}
/**
* @expectedException \yii\base\NotSupportedException
*/
public
function
testUnlinkAllAndConditionDelete
()
public
function
testUnlinkAllAndConditionDelete
()
{
{
$this
->
markTestSkipped
(
'https://github.com/yiisoft/yii2/issues/5136'
);
/* @var $customerClass \yii\db\BaseActiveRecord */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\BaseActiveRecord */
$orderClass
=
$this
->
getOrderWithNullFKClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
$this
->
assertEquals
(
3
,
$orderClass
::
find
()
->
count
());
$customer
->
unlinkAll
(
'expensiveOrdersWithNullFK'
,
true
);
}
}
// TODO test AR with not mapped PK
// TODO test AR with not mapped PK
...
...
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