I delete watson-conversation's Entities by mistake.
Where I can find it and restore it,
or I lost it?
Related
I have several entities with relationships between them, and when I delete an entity related to another entity, the two entities are deleted. This is what I want. However, I would like to know which one is deleted last. So I have a listener "preremove" which is called twice. Once for the first entity, a second time for the second. But I do not know which one is deleted last. Do you have any ideas? thank you in advance
Check tables foreign keys. If your tables have OneToMany relation, record which stores foreign key, will be deleted first.
I'm building an app that allows a user to create reports for advertisers. The entities are set up so that there is a relation between the Report object and the Advertiser object - so that the advertiser has a getReports() method to get them.
I would like to change the app so that instead of actually deleting entities, that it simply changes a "deleted" property to true. That part is no problem, but I'm unsure how to make it so that the getReports() on the Advertiser entity only returns reports for the advertiser that have a deleted property of false.
Please let me know if you have any suggestions how that should be done in accordance with Symfony best practices.
You should look into Gedmo Doctrine Extensions. http://atlantic18.github.io/DoctrineExtensions/
Specifically for your case:
http://atlantic18.github.io/DoctrineExtensions/doc/softdeleteable.html
TLDR; they allow you to configure behavior of your entities in a way you desire, so for example when you "delete" an entity, Gedmo's listeners would set it's deleted value to a current datetime. Now you'd still have that record in your database but with not null value of deleted column marking it 'soft deleted', so when querying, it wouldn't be returned (because Doctrine knows how to query these stuff and would add a condition i.e.: ... where deleted ...) unless you explicitly say you want to see those soft deleted records.
So let's say I have two tables: permissions, and sort of a join table between users and permissions that we'll call permission_list
permission_list has user_id and permission_id.
permission has the name of the permission and a keyname for use elsewhere in the code.
Now I have an assign permissions page, that currently uses a dropdown list of all the available permissions. What I want to have is a list of checkboxes, where permissions in the users list are checked already, and unchecking them removes those records, and checking new ones adds new records.
Does Symfony2 have a built-in way to go about this?
Does this answer your question How to render a checkbox that is checked by default with the symfony2 Form Builder?
Form Builder has a lot of great features that will help you accomplish what you are looking for.
That link references this link http://symfony.com/doc/current/book/forms.html that has a ton of info but he gives a good suggestion. Let me know if thats not clear enough.
What is the best practice for checking if any references to a particular model record exist before deleting that record? Basically, I have a model that represents images, and all metadata associated with an image. Other models will have references to one or more images (depending on the model).
Let's say for example, I have an "Item" which has a "MainImage" and an "AltImage", both of which are just references to the Image model. If I delete an Item record, I have to check if the two images are referenced by any other Item, or any other table, and if not then delete the Image.
How would I go about this?
Since you are using a database, let it maintain referential integrity using foreign key constraints on the images. The database or EF will prevent you from deleting the image if it is still being referenced. You can catch this exception and continue processing the request without deleting the image.
I found a blog posting Inferring Foreign Key Constraints in EF that may be of use in setting these up.
Couple ideas based on what you prefer:
Create trigger in you DB
That will delete alt img.
and everytime you want to delete the main record row the other record will be deleted too.
Another (based on nhibernate)
Make sure that alternative image in your entity framework might have possibility to cascade commands. And in that case if you delete one image the other one will be deleted too. Here is one example from google how to do this
Most clumsy but easiest is:
Delete both records when you deleting the image.
I have an entity generated from my database that contains one table. When i make changes in the DB i obviously would like these changes to reflected in my model.
My current approach is to delete the item from the designer and then right-click - update model from database. This works for me at the moment. Is there a different approach to refreshing these entity tables ?
Why are you deleting them? You can simply right click on your model and select Update Model From Database... and you are done.