Gidi Sprintzin
Gidi Sprintzin

Reputation: 465

How to delete specific field using Objectify?

I'm trying to delete specific field from my DB table. But unfortunately unsuccessfully. I tried this code:

Query<Movie> query = ofy().load().type(Movie.class).filter("name =", "movie name");
        QueryResultIterator<Movie> queryIterator = query.iterator();
        while (queryIterator.hasNext()){
            Movie m = queryIterator.next();
            if(p.getYear()!= null){
                ofy().delete().entity(p.getYear()).now();

            }
        }

I also tried this:

Movie m = ofy().load().type(Movie.class).id("movie id").now();
        List<Long> actors = m.getActor();
        ofy().delete().entity(actors).now();

But it also didn't work. What did i miss?

Upvotes: 0

Views: 424

Answers (1)

konqi
konqi

Reputation: 5227

You need to set the property to delete to null and then save the entity. A delete will delete the whole entity, not any single property.

Example:

Movie m = ofy().load().type(Movie.class).id("movie id").now();
m.actors = null;
ofy().save().entity(m).now();

Upvotes: 0

Related Questions