On Wednesday, March 14, 2018 at 7:32:18 AM UTC-4, Simona Chovancová wrote:
>
> Hello, I have a problem with select.. I have these tables defined:
> db.define_table(
> 'email',
> Field('recipient', 'string', notnull=True),
> Field('subject', 'string', length=256, notnull=False),
> Field('body', 'text', notnull=False),
> Field('html_body', 'text', notnull=False),
> )
>
> self.db.define_table(
> 'attachment',
> Field('file_blob_id'),
> Field('email_id', db.email, notnull=False)
> )
>
> When I insert something into email table and make select like
> db(db.email).slelect(), it returns something like this:
>
> <Row {'recipient': '[email protected]', 'subject': 'sub', 'body':
> 'randomtext', 'html_body': '', 'attachment': <Set (attachment.email_id =
> 27)>, 'id': 27L}>
>
>
The "attachment" attribute of the Row object is not a field that has been
selected from the database and does not involve any data being retrieved
from the database. Rather, it is simply a DAL Set object that can be used
to retrieve related records from the db.attachment table -- you would use
it as follows:
attachments_associated_with_this_email = row.attachment.select()
For details,
see
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Recursive-selects.
If you really need to get rid of that attribute for some reason, you can do
so via:
db(db.email).select(cacheable=True)
When cacheable=True, the DAL excludes any Row attributes that cannot be
pickled, such as the "update_record", "delete_record", and any Set
attributes.
Anthony
--
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.