cakephp3-soft-delete's People
Forkers
davidyell miznokruge marcon100 oxifreshcarpetcleaning hareshpatel1990 mojatter ivyhjk steffenborup waqarakbar ravage84 alexsmonte jtony2976 inimist ks-ocean otterlyolive oxicode isemantics tomohiroukawa funayaki devcorrelator andrecalistro gabrielapg rioastamal mariocahyadi borantula dariob salines nelsonota kamechang adoultremont ken-b4u kakaeriel fredckl ikeda-ye alusev mnmljp tako2487 hasegawa-tomoki luukau aokazu iuvabo davalb imo-tikuwa djaxel igross-co-jp bcalacity ichikawa1024 crasco-technologycakephp3-soft-delete's Issues
Soft deleting not propagating to associations
I have a simple setup in Cake 3.2.5 (also tried with 3.3.1)
Clients hasMany Addresses
Clients hasMany Contacts
Both associations with:
'cascadeCallbacks' => true
'dependent' => true
All the three models have the SoftDelete behavior loaded. No others behaviors loaded in this example.
Whenever I delete()
a client, I expect all related addresses and contacts to be soft deleted, as stated in the documentation. https://github.com/PGBI/cakephp3-soft-delete#soft-deleting--associations
Still, only the client gets soft deleted, while addresses and contacts are left dangling in the database.
I tried the same setup with just commenting out the $this->addBehavior('SoftDelete');
in the three models. The cascading works as expected: main row and associated rows get deleted.
Also, I tried to comment out the $this->addBehavior('SoftDelete');
only in the Client model. This time, the client row gets deleted, while the related rows do get soft deleted.
Can't execute the validation of uniqueness in using this plugin .
I have this validator.
$validator
->requirePresence('name', 'create')
->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table', 'message' => 'must be unique !'])
->notEmpty('name', 'cannot be empty!');
Without using this plugin, patchEntity method returns validation errors correctly.
But using this plugin, patchEntity method returns no validation errors.
receive depreciate error
App\Model\Table\UsersTable::connection() is deprecated. Use setConnection()/getConnection() instead. - /vagrant/app/vendor/pgbi/cakephp3-soft-delete/src/Model/Table/SoftDeleteTrait.php, line: 39
You can disable deprecation warnings by settingError.errorLevel
toE_ALL & ~E_USER_DEPRECATED
in your config/app.php. [CORE/src/Core/functions.php, line 307]
PHP version: 7.0.30
CakePHP version: 3.6.2
Soft deleted records should be fetched for belongsTo association queries.
Hi,
I have been using your script for couple of my projects. Thanks for sharing it.
I have invoices that has a belongs to relation with clients model. When a client is soft deleted, all of its invoices shows empty clients array. Does this make sense that even if records is soft deleted, it should show up in belongs to relations? If so, how can that be implemented?
Thanks
Hard deleting with associations
From what I can see, this doesn't cascade the hard deletes to the associated models (the way it does for soft-deletes) or am I missing something ?
pagination can't view softDeleted item.
Hi, I'm trying to display softDeleted item on pagination. it seems doesn't work to me.
$this->paginate = [
'contain' => ['Users', 'WeatherCategories'],
'order' => [
'Posts.created DESC'
],
'limit' => 50
];
}
$posts = $this->paginate($this->Posts->find('all',['withDeleted']))->toArray();
or
$this->paginate = [
'withDeleted',
'contain' => ['Users', 'WeatherCategories'],
'order' => [
'Posts.created DESC'
],
'limit' => 50
];
}
$posts = $this->paginate($this->Posts->find())->toArray();
is there a way just to display the softdeleted item?
Matching query clauses use wrong alias
I have a Users table and a UserLoginCredentials table.
A User hasMany LoginCredentials, and in that association the targetTable has manually been set to the UserLoginCredentials table.
If I now create a query with a matching clause, the following SQL is generated and will (of course) not properly execute.
SELECT [a lot of selects] FROM users Users INNER JOIN user_login_credentials LoginCredentials ON (LoginCredentials.identifier = :c0 AND Users.id = (LoginCredentials.user_id) AND UserLoginCredentials.deleted IS NULL) WHERE Users.deleted IS NULL LIMIT 1
I have checked the code and could not easily find something to fix this, but I find it curious that the original query object has the correct repository name (LoginCredentials
) while this name is not present in the triggerBeforeFind
function in which the deleted statement is added.
Perhaps something to fix in the future.
Behavior
Hey man,
Am I allowed to convert this awesome trait to a behavior for the Cake 3 Utils Plugin? It would be easier to implement, and could be documented at http://cakemanager.org/docs/utils/1.0/.
Greetz
Bob
How to restore soft deleted record
Dear owner.
Please provide function restore to restore soft deleted record.
I'm sorry if i miss something.
Query::delete() still hard delete
First of all, it's an awesome plugin you have written. Unfortunately I have a problem in combination with FriendsOfCake/crud and the bulk delete action. As you can see here the bulk delete action uses Query::delete()
to build the delete query. This will generate a hard delete query which is not modified from the soft delete plugin. Probably this issue also occurs in other use cases than crud.
A possible solution would be to overwrite the delete()
method inside ORM/Query.php
which already exists in your plugin. @PGBI What do you think?
[Enhancement] Adding the possibility to select 'onlyDeleted' like we do with 'withDeleted'
Hi @davidyell ,
Thanks for this plugin 👍 ,
If we pass the 'withDeleted' option to the finder $Table->find('all', ['withDeleted'])
we will have all the rows(like we disable the plugin) but what if we want only the deleted rows !
I modified your code like this:
public function triggerBeforeFind()
{
if (!$this->_beforeFindFired && $this->_type === 'select') {
parent::triggerBeforeFind();
$aliasedField = $this->repository()->aliasField($this->repository()->getSoftDeleteField());
if (is_array($this->getOptions()) && in_array('onlyDeleted', $this->getOptions())) {
$this->andWhere($aliasedField);
}else if (!is_array($this->getOptions()) || !in_array('withDeleted', $this->getOptions())) {
$this->andWhere($aliasedField . ' IS NULL');
}
}
}
Now we can pass the option 'onlyDeleted' like we do with 'withDeleted' to the finder :)
Problem with query->orWhere()
Hi,
can you please read this ticket cakephp/cakephp#6407 ?
Thank you!
Auth login not working with sofdelete plugin
// \App\Model\Table\Users
use SoftDelete\Model\Table\SoftDeleteTrait;
class AqiUsersTable extends Table
{
use SoftDeleteTrait;
after adding above code $this->Auth->login() stop working. but If I comment "// use SoftDeleteTrait;" auth login works fine. I try to debug, It seems like this issue is somehow related to triggerBeforeFind function inside SoftDelete\ORM\Query. can you please take some time to debug this.
This plugin is works like charm only login not working. please help if possible.
withDeleted parameter is not passed to contained tables
When I execute get query on Model with Model2 and Model3 associated (Model2 and Model3 also use SoftDeleteTrait) I'm getting only Model2's and Model3's rows where deleted is null instead of all records.
$this->Model->get($id, [
'withDeleted',
'contain' => [
'Model2',
'Model3'
]
]);
Allow custom data type for $softDeleteField
I find really useful been able to declare a custom $softDeleteField
since sometimes we are tight to whatever convention the original designed decided to use. However, for the same reason, some people do not use a timestamp for their deleted fields; it would be really useful to been able to define both the deleted field (e.g. isdeleted), but also the data type (e.g. boolean).
Validation IsUnique problem with softdeleted item
Can´t use IsUnique when there is an item softdeleted, the validation ignore it and the DB return "Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry".
make compatible with cakephp 4
On December 16th cakephp 4 was released. Are there plans to make this this behaviour compatible with the new cakephp version? Or is somebody already working on a fork updating it?
Thanks!
softdelete update for cakephp 3.6
While using dev-master of softdelete for a project with cakephp3.6, I got "X is deprecated, use Y"
warnings. I think only a couple of things need to be changed. Below is some things I changed locally:
SoftDeleteTrait.php - Line 39: connection() -> getConnection()
SoftDeleteTrait.php - Line 25: schema()>column( -> getSchema()->getColumn(
SoftDeleteTrait.php - "primaryKey()" to "getPrimaryKey()" ( I think )
Query.php - Line 25: repository() -> getRepository()
Maybe I've missed a version of soft-delete that already has/supports this, then this ssue may be closed.
Thanks for your work.
deleteAll doesn't delete associations
The deleteAll()
does not delete the associations however it is all fine with a single row deleting as we have cascadeDelete()
in _processDelete()
, but not in deleteAll()
.
Non-configured delete field can delete all records
Setup
My setup is that I have boolean deleted
and datetime deleted_date
.
What I did
Added the Trait to my table and called hardDeleteAll()
.
What happened
All records in my table were deleted.
What I expected to happen
I would expect no records to be deleted, or an exception to be thrown if the default field doesn't exist in the Tables schema. Perhaps something like $entity->has($field)
Possibility to "contain" deleted records from join table
Hey!
I have a relationships with Forms
belongsToMany Products
- where I want to retain the joinData in the forms_products
table, no probs - I just include SoftDelete on the FormsProducts
model.
Although I'm having issues getting the data I want - I can do a $this->FormsProducts->find('all', ['withDeleted'])->where([........]);
but I can't do a $this->Forms->find('all', ['withDeleted'])->contain(['Products' => *conditions*])
Or am I simply wrong, and not hitting the correct syntax or something alike?
Docs error: error with syntax in documentation
On the page https://github.com/PGBI/cakephp3-soft-delete#restoring-soft-deleted-records it should be:
$user = $this->Users->find('all', ['withDeleted'])->where(['id' => 1])->first();
Saving anyone who copies and pastes the sample for testing a few minutes. I copy and pasted and it took me a few minutes to figure out why it wasn't working. I'm using version 3.3 if this happens to be version specific.
Problem with belongsToMany queries
Esample:
PostsTable belongsToMany LabelsTable
In the database, each posts
, labels
, labels_posts
has deleted
field.
Database has these records:
posts (id, title, deleted):
(1, 'First article', null);
labels (id, title, deleted):
(1, 'First label', null),
(2, 'Second label', null);
labels_posts (id, post_id, label_id, deleted):
(1, 1, 1, '2015-05-05 11:48:27'),
(2, 1, 2, null);
When I select posts, both first and second labels are selected and associated to the article despite the deleted record in the bridge.
Here is the generated sql:
SELECT Posts.id AS `Posts__id`, Posts.title AS `Posts__title`, Posts.deleted AS `Posts__deleted`
FROM posts Posts
WHERE Posts.deleted IS NULL
ORDER BY Posts.id DESC
LIMIT 20
OFFSET 0
SELECT LabelsPosts.label_id AS `LabelsPosts__label_id`, LabelsPosts.id AS `LabelsPosts__id`, LabelsPosts.post_id AS `LabelsPosts__post_id`, LabelsPosts.deleted AS `LabelsPosts__deleted`, Labels.id AS `Labels__id`, Labels.title AS `Labels__title`, Labels.deleted AS `Labels__deleted`
FROM labels Labels
INNER JOIN labels_posts LabelsPosts
ON Labels.id = (LabelsPosts.label_id)
WHERE (LabelsPosts.post_id in (:c0) AND Labels.deleted IS NULL)
So Query does not add deleted condition to LabelsPosts.
Thank you!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.