reflexive relation

17 views
Skip to first unread message

GN

unread,
Nov 6, 2013, 3:03:18 AM11/6/13
to mong...@googlegroups.com
I want to know how to create a reflexive relation with members of the same class. 

class MetaType(Document):
collection_name = "MetaTypes"
 structure = {
    'description': basestring,              # Description (name)                        
                                                 
        'parent': [MetaType]                                                                                   
         }

This gives a validation error.  However, when I try to express relations to other classes this is not a problem. How do we take care of the problem?

thanks

--
GN

Nicolas Clairon

unread,
Nov 18, 2013, 8:09:11 AM11/18/13
to mong...@googlegroups.com
Hi,

The simplest solution is to set the 'parent' field as empty array. The only issue is that this part of this structure won't be validated.

class MetaType(Document):
   __database__ = 'test'
   __collection__ = 'meta_types'
   structure: {
      'description': basestring,
      'parent': []
   }



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

Nagarjuna G

unread,
Nov 19, 2013, 11:44:32 PM11/19/13
to mong...@googlegroups.com
On Mon, 2013-11-18 at 14:09 +0100, Nicolas Clairon wrote:
> Hi,
>
>
> The simplest solution is to set the 'parent' field as empty array. The
> only issue is that this part of this structure won't be validated.
>
>
> class MetaType(Document):
> __database__ = 'test'
> __collection__ = 'meta_types'
> structure: {
> 'description': basestring,
> 'parent': []
> }
>

In this case, quite a lot of possible values could go. We thought of
the following:

structure = {
'description': basestring, # Description (name)
'parent': ObjectId #
}

Here at least only an existing document id could go. The plan is to
write a validator that will restrict the scope of ObjectIds to those
of the current class.

thanks
--
GN




Nicolas Clairon

unread,
Nov 22, 2013, 3:19:23 AM11/22/13
to mong...@googlegroups.com
It will do just fine :)



thanks
--
GN




Reply all
Reply to author
Forward
0 new messages