Thanks Nick.  Always appreciate the help!

Regarding the prefix you put in the key_name, on hunch it looks to  
have other benefits.  I suspect memcache.  Do you have any other  
pearls you can toss out about it, and ways that known key_name  
prefixes can be leveraged?

--Daniel Rhoden


On Aug 17, 2009, at 5:21 AM, Nick Johnson (Google) wrote:

> Hi Daniel,
>
> The best way to ensure uniqueness is to use key names. In this case,  
> the natural key name is the User's ID. For example:
>
> user_account = Account(key_name = 'user:%d' %  
> (current_user.user_id(),), ...)
>
> This also allows you to look up user accounts without a query:
>
> user_account = Account.get_by_key_name('user:%d' %  
> (current_user.user_id(),))
>
> -Nick Johnson
>
> On Mon, Aug 17, 2009 at 2:45 AM, Daniel Rhoden <[email protected]>  
> wrote:
> I discovered that my 'Account' model happily created multiple  
> instances of user '[email protected]' without complaint during  
> testing.  (I know, fix my code).
>
> Short question: What's the lightest way of ensuring value uniqueness  
> between entity values?
>
> I've read up on the Property class constructor argument "validator"  
> and got to wondering if there is a RoR-like library of prefab  
> validators.  It would be great if I could do something like this:
>
> from google.appengine.ext import validation
>
> class Account(db.Model):
>   user  = db.UserProperty(required=True,  
> validator=validation.unique(db.UserProperty) )
>   ...
>
> related resources:
> http://code.google.com/appengine/docs/python/datastore/propertyclass.html
> http://googleappengine.blogspot.com/2009/07/writing-custom-property-classes.html
>
> --Daniel Rhoden
>
>
>
>
>
>
>
>
> -- 
> Nick Johnson, Developer Programs Engineer, App Engine
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to