Hello Scott,

You mention that both results set were the same with and without limitby, I
guess is because the number of record your query return is already 20 or
even less record so, limitby don't kick in and is useless because your data
set has too few records... You also mention that belongs would force your
query to return only unique id, this is false, belongs use a list or a
tuple and the same id can be include multiple time, though it will be
unique if belongs criteria is a unique for a give column in the table such
as the primary key or if you put a unique constains over a foreign key
reference field...

I read this thread rapidly, but to me your issue is coming from not using
orderby or as Anthony mention having an args that would influence the way
query is made by the grid which you can't reproduce when query your self
the db because you don't include the args.

Good luck

Richard

On Wed, Dec 14, 2016 at 2:03 PM, Anthony <abasta...@gmail.com> wrote:

> Sorry, I cannot reproduce running on Ubuntu -- both printouts as well as
> the first page of the grid (after sorting on Myfield2) all have the same 20
> records when I run it. Maybe someone else can try it on OSX. What happens
> if you run the OSX binary version of web2py?
>
> Anthony
>
> On Tuesday, December 13, 2016 at 6:43:57 PM UTC-5, Scott Hunter wrote:
>>
>> If I make a fresh, new app from the Administrative Interface, and replace
>> the contents of default.py with the following, it will print the first 20
>> records that should show up in the grid, first without using limityby (and
>> using a counter to stop at 20), and then with limityby; the second is
>> missing records from the first, and matches what appears on the first
>> sorted page of the grid.
>>
>> {The main contents of views/default/index.html need to be replaced with
>> {{=form}} as well, to see the grid)
>>
>>
>> import random
>> def index():
>>     db.define_table('mytable', Field('myfield1', 'string'),
>> Field('myfield2', 'string'))
>>
>>     f2is1_ids = [x.id for x in db(db.mytable.myfield1=="A").select(
>> db.mytable.id)]
>>     if len(f2is1_ids)==0:
>>         db.mytable.truncate()
>>         for v1 in random.sample(xrange(10000),200):
>>             for v2 in random.sample("ABCDE",3):
>>                 db.mytable.insert( myfield2="Value%05d"%v1, myfield1=v2 )
>>         f2is1_ids = [x.id for x in db(db.mytable.myfield1=="A").select(
>> db.mytable.id)]
>>     query = db.mytable.id.belongs(f2is1_ids)
>>     i = 0
>>     for d in db(query).select(orderby=db.mytable.myfield2):
>>         print "%5d"%d.id, d.myfield1, d.myfield2
>>         i += 1
>>         if i==20:
>>             break
>>     print"---"
>>     for d in db(query).select(orderby=db.mytable.myfield2,limitby=(0,20))
>> :
>>         print "%5d"%d.id, d.myfield1, d.myfield2
>>     args = { 'orderby':db.mytable.myfield1, 'editable':False,
>> 'deletable':False}
>>     form = SQLFORM.grid(query, csv=False, details=False,
>> searchable=False, create=False,
>>             paginate = 20,
>>             orderby=db.mytable.myfield1, editable=False, deletable=False)
>>     return locals()
>>
>>
>> On Tuesday, December 13, 2016 at 3:01:19 PM UTC-5, Anthony wrote:
>>>
>>> While including id may make a difference in general, it should (and did)
>>>> not in this case: the reason for the long belongs list is that queries are
>>>> made to insure that no 2 records with the same Dog_ID appear in that list.
>>>>
>>>
>>> Sorry, I didn't notice that the first field in your print statements was
>>> f_Dog_ID (thought it was just the id field).
>>>
>>> Anyway, it's not clear what the problem is. I suggest you pack and
>>> attach a minimal app that exhibits the behavior.
>>>
>>> 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 web2py+unsubscr...@googlegroups.com.
> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to