Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a property from an existing Model instance

I have a Model with a big blob property User.image Having this property in my model made my queries take too much time and go over the deadline so I decided to move that property into another model - UserData - who's parent is the User.

However, existing model instances that are already in the datastore still contain that image data even though the Model definition no longer contains that property.

Is there any, way to delete that data from the User instances?

like image 560
Eran Kampf Avatar asked Jan 06 '10 12:01

Eran Kampf


People also ask

How to remove particular property from an object?

Remove Property from an ObjectThe delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.

How do I remove a property from an object in C #?

You can't remove a property, unless you remove it permanently, for all cases. What you can do, however, is to create multiple classes, in a class hierarchy, where one class has the property and the other hasn't.

How do you remove one property from an object in TypeScript?

To remove a property from an object in TypeScript, mark the property as optional on the type and use the delete operator. You can only remove properties that have been marked optional from an object.

How to delete property on object JavaScript?

In JavaScript, there are 2 common ways to remove properties from an object. The first mutable approach is to use the delete object. property operator. The second approach, which is immutable since it doesn't modify the original object, is to invoke the object destructuring and spread syntax: const {property, ...


1 Answers

The answer to your question is documented here : https://developers.google.com/appengine/articles/update_schema

Copy/paste from the "Removing Deleted Properties from the Datastore" section :

If you remove a property from your model, you will find that existing entities still have the property. It will still be shown in the admin console and will still be present in the datastore. To really clean out the old data, you need to cycle through your entities and remove the data from each one.

  1. Make sure you have removed the properties from the model definition.
  2. If your model class inherits from db.Model, temporarily switch it to inherit from db.Expando. (db.Model instances can't be modified dynamically, which is what we need to do in the next step.)
  3. Cycle through existing entities (like described above). For each entity, use delattr to delete the obsolete property and then save the entity.
  4. If your model originally inherited from db.Model, don't forget to change it back after updating all the data.
like image 174
Franck Avatar answered Oct 11 '22 09:10

Franck