Referential integrity

58 views
Skip to first unread message

xzf...@gmail.com

unread,
Oct 29, 2015, 10:30:39 PM10/29/15
to OrientDB
Hello,

This question was asked in 2013, and Luca's reply was as follows:

On Monday, May 20, 2013 at 6:20:24 PM UTC-4, Lvc@ wrote:If you remove a document is your responsibility to clean all the references.

Does this answer still hold? If yes, how can I find all the references to a class that is about to be deleted? (or what is the recommended way of otherwise dealing with this issue?)

I am using 2.1.2 (trying it out) and I was quite amazed to find that the database allowed me to drop the referenced class and kept the RID of the referenced object (dangling pointer, basically).

The scary thing was that once I created (and populated) another class, the cluster id was reused, and the RID happily pointed to a new, entirely unrelated object.

Thanks!
Dmitri


Luigi Dell'Aquila

unread,
Oct 30, 2015, 3:55:07 AM10/30/15
to orient-...@googlegroups.com
Hi Dmitri,

Document layer does not manage link consistency, just for a matter of performance, but Graph layer does (eg. it removes dangling edges when you delete a vertex). My advice is to use edges instead of links, it will also give you another advantage, that is having bi-directional traversal of pointers

Thanks

Luigi


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

xzf...@gmail.com

unread,
Oct 30, 2015, 5:15:54 PM10/30/15
to OrientDB
Luigi - Thank you. I understand the tradeoff.

OK, I have to manage this manually. What is the best way?

Is there any way to query the schema and find out which objects have fields that reference a particular class? (so that I can NULL them and then remove the class)

Regarding using Graph type: yes, maybe. But I really like the simple dot notation as it works with LINKs. I think it is very elegant. (I take my syntactic sugar wherever I find it)

Luigi Dell'Aquila

unread,
Nov 2, 2015, 5:16:25 AM11/2/15
to orient-...@googlegroups.com
Hi Dmitri,

if you have a full schema defined you can query it with

select customFields from (
    select expand(classes) from metadata:schema 
) where name="YourClassName"

and

select customFields from (
  select expand(properties) from (
     select expand(classes) from metadata:schema 
  ) where name="YourClassName"
) where name="PropertyName"
If you have partial or no schema defined, you can use FIND REFERENCES command 


Just take into consideration  that it scans the whole database, so it's very inefficient

Thanks

Luigi

DmitriR

unread,
Nov 2, 2015, 10:51:50 AM11/2/15
to orient-...@googlegroups.com
Luigi - Thanks a lot! The schema query is perfect.

Dmitri
> You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/IZp9Qw7Kgps/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages