Deleting entities non-destructively in Symfony2 - orm

Is there a good, clean and simple way to delete entities non-destructively in Symfony 2? I'd like to give my administrators a chance to undelete items, while sacrificing as little of the automation provided by the framework as possible.
If there is no built-in solution or third party bundle to help me, what would be the best way to do this? Adding a deleted property to entities would require lots of added logic to keep them from cluttering the controllers created by doctrine:generate:crud, so maybe they should be stored in a separate table in serialized form?

What you want is Soft Delete. There is a Doctrine extension for that and a bundle to integrate it with Symfony.

Related

Symfony2 API with tables without entities

I have legacy code that has DB connected.I'm trying to add new features for this app with Symfony2. I used Theodo Evolution Bundle to access the legacy session.
First thing that I want to do now, is to build an API that will use data from existing database. This database has tables that are not converted to entities. My question is which is best approach in this case. To use native queries from existing tables in database to build API or to convert tables into entities I used documentation for this part but I'm not sure will import all relations and everything) and then to build API. Can you please suggest me which is best approach in this case. Thank you.
The best approach in my opinion is to work with doctrine entities within the framework and to avoid direct SQL if possible. That is the basic philosophy behind frameworks such as Symfony: the database layer should be abstracted.
The entity-database mapping might be quite more of a hassle at first, because you can't rely on automatic tools to set it up, but once it's done it will be much easier to work out the rest of the application.

Audit trail techniques

My project is in ASP.NET MVC3, SQL Server 2008 and using Fluent NHibernate.
I now have a requirement to audit certain properties of a specific object.
i.e. recording the old and new value of the properties changed on that object and also create and delete events on the object itself.
I think there can be several ways to approach this task - database triggers, INotifyPropertyChanged interface, or any NHibernate provided features?
Alternatively any open source libraries that will make my life simpler.
However, what i am not sure about is which path to choose. I mean this is a very vast area where I can go on exploring and still can't come to any conclusion.
It will be really helpful if I can get some guidance as to which option will be best considering my requirement and I can look into it more from there.
Thanks a lot.
Maybe I'm a bit biased but...
Have you had a look at Envers? https://bitbucket.org/RogerKratz/nhibernate.envers

Symfony 2 : Location of Entities

I'm pretty new at Symfony 2 and I was wondering something :
Let's assume I have 2 bundles in my projects. I want to use entities generated from my database in both bundles.
Where am I suppose to generate the entities ? (To me the best way would be outside the bundles but I can't find out how to do that)
Thanks for your help.
I think there is two solutions, you have to think of the design of your application.
Are you sure you need two bundles ? If the link is so strong between the two, why didn't you choose to make only one bundle ? In this case, you'll just have to generate the entities into this bundle.
Other case : you effectively need two bundles, but in this specific application you need to make a link between the two. In this case, I think you should generate the entities in the bundle where it belongs, and if you need so you can use them in another bundle (thank to use MyApp\MyBundle\Entities\...;). You have to think in terms of generic code when using Symfony, in order to be able to reuse your bundles in other projects. ;)

How do you manage your ORM layer when database undergoes changes?

I understand the reason behind not auto refreshing your .dbml (Linq2Sql), .edmx (Linq2Entities) or .hbm.xml (NHibernate). In each of these ORM solutions you need to update these files if you have changes in the database. Is there a way to refresh these files automatically if you are 100% sure that it wont break anything?
I am reasonably familiar with Migrations in RoR. Is there a dependabale Migration tool in the .NET world ?
In general, how do you stay agile with database design and dont recreate these mapping files manually again and again?
Please provide a link if this question is a duplicate. I was not able to find one.
I'm not sure what your hesitation about updating the EDMX is. Just go ahead and update your model from the database. Chances are very good it will work. But if it doesn't, just get the old version from source control, and make the changes manually.
With LINQ to SQL, on the other hand, it's harder, because there is no update feature. You have to remove the changed objects from your model, re-add them, and re-apply any changes you have made, manually. Again, source control is vital here; you'll want to diff the XML files from the previous version to make sure you didn't forget anything.
I'm not sure what your question about migrations means. Yes, there is a tool (RikMigrations), which does a similar thing as migrations in Rails. But migrations, of course, change your database metadata. They don't change your ORM mapping. That's done elsewhere, both in Rails and in .NET.

Nhibernate and History Tables

I am working on a ASP.NET MVC website using Nhibernate as my ORM. The project is similar to a wiki/blog engine and requires that as pages are edited they store a history of the edits in another table which can then be viewed and recovered. This is complicated somewhat in that each "page" can have collections associated with it that can also be edited/added/removed. I would also need to stored these changes.
I was wondering how this fits into an entity mapping scenario such as Nhibernate and how this might be implemented. If anyone knows of any articles on this, or has done this themselves then please let me know.
I was considering triggers but I would prefer not to mix data access technologies if possible. I also am using MySql so CDC would not be possible for me.
Thanks
Either implement an auditing interceptor or use the event system. The event system is newer, I haven't found any auditing examples yet...
Also see this related question:
Take a look at NHibernate.Envers https://bitbucket.org/RogerKratz/nhibernate.envers