Never used mongo but what happens if you assign row.gender  to a var ?

2014-11-14 16:55 GMT+00:00 Francisco Costa <[email protected]>:

> Hi,
>
> I'm unable to fully convert a dict into a Row(), specially if there is a
> foreign key (ObjectId)
>
> I have the following code (I've commented the prints):
>
> db = DAL(
>     'mongodb://localhost/%s' % request.application,
>     pool_size=10,
>     adapter_args={'safe': False},
>     check_reserved=['all']
> )
>
> db.define_table(
>     'genders',
>     Field('id', required=True, unique=True),
>     Field('name', 'string', length=128, required=True),
>     format='%(name)s'
> )
>
> db.define_table(
>     'auth_user',
>     Field('id', required=True, unique=True, writable=False, readable=False
> ),
>     Field('name', 'string', length=128, required=True),
>     Field('gender', db.genders, required=False, default=None),
>     format='%(name)s'
> )
>
> from gluon.dal import Row
>
> mongo = db._adapter.connection  # Use PYMONGO
>
> user = mongo.auth_user.find_one({'name': 'Francisco Costa'})
> print(user)
> #    {
> #        u'name': u'Francisco Costa'
> #        u'city': u'Porto',
> #        u'gender': ObjectId('51c1e89a03d36d6fa90ce06c')
> #    }
> print(Row(user))
> #    <Row {
> #        u'name': u'Francisco Costa',
> #        u'city': u'Porto'
> #    }>
> user = db(db.auth_user.name=='Francisco Costa').select().first()
> print(user)
> #    <Row {
> #        'name': 'Francisco Costa',
> #        'city': 'Porto'
> #        'gender': 25302706908812871434930806892L,
> #    }>
>
>
> As you can see when I * print(Row(user)) *the *gender* is not shown.
>
> How to solve this?
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to