You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Patrick Barnes <mr...@gmail.com> on 2009/11/19 00:16:28 UTC

Foreign key checking?

I have a 'user', a 'group', and a 'role' doctype in my database.

The user<->group relationship is many-to-many. (through the role)

Roles have their own data (for instance, automatic expiry dates)

When a role document is created, is there a way for validate_doc_update 
to check that the user and group the role refers to exist? I don't want 
orphan roles to be able to be created.
(Alternatively: Is there a better way to do this?)

-Patrick Barnes

Re: Foreign key checking?

Posted by Paul Davis <pa...@gmail.com>.
On Wed, Nov 18, 2009 at 6:16 PM, Patrick Barnes <mr...@gmail.com> wrote:
> I have a 'user', a 'group', and a 'role' doctype in my database.
>
> The user<->group relationship is many-to-many. (through the role)
>
> Roles have their own data (for instance, automatic expiry dates)
>
> When a role document is created, is there a way for validate_doc_update to
> check that the user and group the role refers to exist? I don't want orphan
> roles to be able to be created.

Assuming you're not deleting groups very often, check if it exists
before saving.

> (Alternatively: Is there a better way to do this?)
>
> -Patrick Barnes
>

Paul Davis