tag:blogger.com,1999:blog-3825636150904136311.post2234776952290889341..comments2024-02-13T15:01:56.008+01:00Comments on Symfony world: Doctrine SoftDelete behavior usageTomaszhttp://www.blogger.com/profile/08377176323730229843noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-3825636150904136311.post-85563826766072735032013-08-21T10:26:09.236+02:002013-08-21T10:26:09.236+02:00Hi...
Did you get the solution for this?
where to ...Hi...<br />Did you get the solution for this?<br />where to override the softdelete.php file?<br /><br />-Thanks,<br />MonishAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-4948072072621084302011-07-25T22:57:03.780+02:002011-07-25T22:57:03.780+02:00i found a solution for the relations (cascade) at ...i found a solution for the relations (cascade) at http://blog.elinkmedia.net.au/2010/01/30/doctrine-tricks/<br /><br />here an example that worked for me:<br /><br /># a question has many answers<br />Question:<br /> actAs:<br /> SoftDelete: ~<br /> columns:<br /> title: string(200)<br /> relations:<br /> Answers:<br /> class: Answer<br /> local: id<br /> type: many<br /> foreign: question_id<br /> cascade: [delete]<br /><br />Answer:<br /> actAs:<br /> SoftDelete: ~<br /> columns:<br /> title: string(200)<br /> question_id: integerAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-89744422676015486892011-07-24T12:37:43.345+02:002011-07-24T12:37:43.345+02:00It's easy! It works the same way as other doct...It's easy! It works the same way as other doctrine behaviors - modify schema YAML files:<br /><br />ProductQuantityHistory:<br />__comment: "historia liczebności produktów"<br />__actAs:<br />____Timestampable:<br />______updated:<br />________disabled: true<br />____Signable:<br />______updated:<br />________disabled: true<br /><br />and so a SoftDelete can be defined in the following way:<br /><br />ProductQuantityHistory:<br />__comment: "historia liczebności produktów"<br />__actAs:<br />____SoftDelete:<br />______name: is_deleted<br />______type: datetime<br /><br />PS sorry for the delay - I've been on a vacation ;)Tomaszhttps://www.blogger.com/profile/08377176323730229843noreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-10108727192278216482011-07-18T14:54:14.981+02:002011-07-18T14:54:14.981+02:00how does one configure softdelete? I see the file ...how does one configure softdelete? I see the file in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Template/softDelete.php. And in this file I see the options array. So I know I need to set those options some how. But we know we should not directly edit this file so I need to override this softDelete.php, but I do not know how to do that. Any info? Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-37930769049420344532011-06-15T10:15:43.818+02:002011-06-15T10:15:43.818+02:00Well, two things !
First, your question made me r...Well, two things !<br /><br />First, your question made me re-thought about the business rules I had to achieve. In fact, as you mentionned, it seems weird to use SoftDelete in some cases and hard deletes in other cases on the same model. <br /><br />And the thing is I should not do that but rather :<br /> - unlink a given instance with other model instances ;<br /> - or hard delete my instance whenever it is not linked with other model instances.<br /><br />Second, I found a trick on a website to be able to easily query a table (in DQL) to include the soft deleted records. It may be useful to anybody using the SoftDelete behaviour !!<br /><br />http://blog.yoda-bzh.net/index.php?post/2010/04/06/Doctrine%3A-Howto-bypass-the-SoftDelete-behaviourAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-76374511331388434612011-06-15T08:22:19.546+02:002011-06-15T08:22:19.546+02:00It's quite strange that you need SoftDelete an...It's quite strange that you need SoftDelete and normal delete at the same time. Some model should be deleted either normally or softly. I guess there is no 'clean' solution here. You can try to remove records from the database, using raw SQL queries (but your solution seems better to me).<br /><br />By the way, could you describe why do you need to have a dynamic SoftDelete behavior for a model? I'm just curious...Tomaszhttps://www.blogger.com/profile/08377176323730229843noreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-76711006903275269742011-06-14T17:35:22.196+02:002011-06-14T17:35:22.196+02:00Hi, thanks for the tips !
I would have a question...Hi, thanks for the tips !<br /><br />I would have a question about the way to use SoftDelete.<br /><br />In the application I am doing, I am using the SoftDelete on a table, but sometimes I might need to really delete a record from that table. <br /><br />I have a way to do it, but that seems a really bad manner as long as I have to do:<br /><br />Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false);<br />**do the deletion**<br />Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);<br /><br />Is there a better of doing this ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-34508397900905393072011-03-11T14:28:50.830+01:002011-03-11T14:28:50.830+01:00thanks a lot dude!thanks a lot dude!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-51414944845094375882011-02-04T23:14:27.127+01:002011-02-04T23:14:27.127+01:00I Love this, i had implemented this manually and w...I Love this, i had implemented this manually and was WAY harder, Thanks!!~Freedom~https://www.blogger.com/profile/07974508402481579760noreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-80360640567083072852011-01-12T13:48:16.507+01:002011-01-12T13:48:16.507+01:00The correct link is
http://www.symfonyreference.co...The correct link is<br />http://www.symfonyreference.com/schema-ymlAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-57811413094126511482010-12-28T21:00:34.628+01:002010-12-28T21:00:34.628+01:00See symfony schema.yml reference in addition to th...See symfony schema.yml reference in addition to this tutorial: http://www.symfonyreference.com/schemaRutahttp://www.symfonyreference.com/schemanoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-72867430497116396872010-11-30T10:35:00.337+01:002010-11-30T10:35:00.337+01:00thanks for providing this useful tutorial!thanks for providing this useful tutorial!Matze Penghttps://www.blogger.com/profile/14797869438470907034noreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-37079147603210066932010-11-29T09:05:33.008+01:002010-11-29T09:05:33.008+01:00your can enable DQL callbacks in database.yml (and...your can enable DQL callbacks in database.yml (and other doctrine attributes):<br /><br />all:<br /> doctrine:<br /> class: sfDoctrineDatabase<br /> param:<br /> dsn: mysql:dbname=test;host=localhost<br /> username: test<br /> password: test<br /> attributes:<br /> default_table_collate: utf8_general_ci<br /> default_table_charset: utf8<br /> use_dql_callbacks: trueAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-39266659737852288472010-11-13T10:36:48.859+01:002010-11-13T10:36:48.859+01:001) When DQL callbacks are enabled it is safe to tr...1) When DQL callbacks are enabled it is safe to try to delete records without using Doctrine_Record::delete(), because there is a method "preDqlDelete" in SoftDelete Listener and takes care of proper data handling.<br /><br />2) If delete time is irrelevant you can also configure SoftDelete to use boolean value is/isn't deleted (instead of timestamp).Axinethttp://axi.net.plnoreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-54863193570307297712010-11-01T13:59:04.579+01:002010-11-01T13:59:04.579+01:00Khepin, you're right. Thanks you for yur sugge...Khepin, you're right. Thanks you for yur suggestion - the article is now updated.Tomaszhttps://www.blogger.com/profile/08377176323730229843noreply@blogger.comtag:blogger.com,1999:blog-3825636150904136311.post-22007167154957952152010-11-01T12:12:13.615+01:002010-11-01T12:12:13.615+01:00Actually you don't need to take care of the de...Actually you don't need to take care of the deleted elements by overriding the buildQuery() method.<br />You can just enable DQL callbacks from the Doctrine configuration. In ProjectConfiguration.class.php, add:<br /> public function configureDoctrine(Doctrine_Manager $manager)<br /> {<br /> // Enable callbacks so that softDelete behavior can be used<br /> $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);<br /> }<br /><br />Then Doctrine automatically filters out the rows having a deleted_at that is not null.Mr. Khttp://sf.khepin.comnoreply@blogger.com