Grr, And now I can't get the db.item_version.ALL without Postgresql
panicking about not having the item in the group buy. How do I get the
fields in the result set? Do I need to place it in as a belongs or
something?
latest_versions = db( (db.item.id == db.item_version.artifact_id) &
(db.item_version.id > 0)
).select(db.item.ALL, db.item_version.ALL,
db.item_version.version_date.max(), groupby=db.item.id)
On Thursday, August 25, 2016 at 8:29:09 AM UTC+3, Encompass solutions wrote:
>
> Does this seem sensible? It seems to work with my initial tests.
>
> latest_versions = db( (db.item.id == db.item_version.artifact_id) &
> (db.item_version.id > 0)
>
> ).select(db.item.ALL,db.item_version.version_date.max(), groupby=
> db.item.id)
>
> the .max() feature, at least what I found, was totally undocumented.
> We should have an example database as part of the documentation with a
> collection of examples around it so we can all relate better. :/
>
> On Monday, August 22, 2016 at 10:52:55 AM UTC+3, Encompass solutions wrote:
>>
>> Consider the following pseudo model.
>>
>> item
>> ->name = "string"
>>
>> version
>> ->item_id = item.id
>> ->version_date = "datetime"
>>
>>
>> While I can easily create a collection of the item with it's versions.
>> all_items = db((db.item.id > 0) & (db.version.item_id == db.item.id
>> )).select(orderby=db.item.name | db.version.version_date)
>>
>> How do get just all items with just the latest version of each item
>> without having to do this....
>> items = []
>> current_id = all_items.first().item.id
>> for thing in all_items:
>> if thing.item.id != current_id:
>> current_id = thing.item.id
>> items.append(thing)
>>
>> It seems a bit silly and heavy to be doing this especially since my data
>> could get quite large. I imaging the database has some way to do this,
>> just never learned how.
>>
>> Ideas on how this could be done?
>>
>> BR,
>> Jason Brower
>>
>>
--
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.