google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Remove reference List #239

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I use morphia to do a demo with version of 0.98.
I have a problem about removing a list,that is annotationed @Reference.
Something like this :
@Entity(value="role",noClassnameStored=true)
public class A {
    @Id
    private ObjectId id;
    //getter and setter
}

public class B {
    @Id
    private ObjectId id;
    @Reference
    List<A> list = new ArrayList<A>();
    // getter and setter
}
I want to delete an Object of A.I know I should delete all the reference about 
A.The problem is how to delete it.

Original issue reported on code.google.com by lfjoba@gmail.com on 8 Mar 2011 at 3:31

GoogleCodeExporter commented 9 years ago
It is best to ask these kinds of questions on the list: 
http://groups.google.com/group/morphia

The easiest way is to get the list and call ds.delete(aInstance) in a for loop 
for each item in the list.

The fastest way is to turn that into a List<Key<A>> field in your B class, and 
then collect the id values and issue a query with the id in that list.

We can add some helper methods to simplify the process of converting a list of 
Key<T> to a list of their id values for the in query; it makes sense since you 
would use the same method to get those entities if you are resolving things 
yourself.

Original comment by scotthernandez on 8 Mar 2011 at 3:55

GoogleCodeExporter commented 9 years ago
Thank you for your reply!
I will try it later.
And the link,http://groups.google.com/group/morphia,in my country,reset by 
somebody.I will ask thess kinds of questions on the list.

Original comment by lfjoba@gmail.com on 8 Mar 2011 at 4:15

GoogleCodeExporter commented 9 years ago
Hi scotthernandez
I tried your suggestion:The easiest way and The fastest way.
I remove the list by DBRef.
My English is poor.I can understand you suggest.Maybe you should add some 
simple methods to resolve the question .
Thank you!

Original comment by lfjoba@gmail.com on 8 Mar 2011 at 6:10