[web2py] Re: Using parse_as_rest: problem with cross joins?

2019-05-21 Thread Massimo Di Pierro
Will release at the end of the month

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/993d75f1-ac3c-467a-9fa6-ed0dca0f2d3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Using parse_as_rest: problem with cross joins?

2019-05-19 Thread David Orme
Sorry, being dim. The web2py repo links out to pydal, so I can just clone 
web2py/web2py.

Cheers,
David

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f6537025-96bd-4a47-9526-7a45baab2b37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Using parse_as_rest: problem with cross joins?

2019-05-19 Thread David Orme
Hi Massimo,

I saw that announcement shortly after submitting the question. I've 
downloaded the developer source (/static/nightly, with VERSION contents 
"Version 2.18.5-stable+timestamp.2019.04.08.04.22.03") and neither dbapi.py 
(nor it's recent rebranding as restapi.py) is in that zip. Is it reasonable 
to drop a clone of pydal/pydal into packages or is there a release coming 
out shortly with the new api in it?

Thanks,
David

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a0ad4f5c-0431-48a8-9302-f3db54c22c4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Using parse_as_rest: problem with cross joins?

2019-05-17 Thread Massimo Di Pierro
Hello David,

I recommend moving the the new DBAPI (other thread). Do not know the 
parse_as_rest will be supported very much in the near future. Got very 
little traction.

On Friday, 17 May 2019 08:24:13 UTC-7, David Orme wrote:
>
> Hi,
>
> I'm looking at parse_as_rest() to provide an API and can't get it to work 
> as expected. I have two table: datasets and fields, with a 1 to N 
> relationship and I want to create an API that returns datasets that have a 
> field name matching a pattern so (using the tuple version of patterns to 
> provide a pattern, base query and exposed fields).
>
> patterns = [
> ("/field_name/{fields.field_name.contains}/data[datasets.id]", 
> None, None),
> ]
>
> I thought this was fine, but now I want to restrict results to the latest 
> version of datasets either through:
>
> patterns = [
> ("/field_name/{fields.field_name.contains}/data[datasets.id]",  (
> db.datasets.latest == True), None),
> ]
>
> or:
>   
>   parser = db.parse_as_rest(patterns, args, vars, queries=(db.datasets.latest 
> == True))
>
> That was returning datasets that are not the latest version. I stuck a 
> print(dbset._select()) into pydal/helpers/rest.py to try and figure it out. 
> I think that the example in the manual goes from 1 to N (people to pets), 
> whereas here I am going from N to 1 (fields to datasets) and the underlying 
> SQL from that select is performing a cross join:
>
> SELECT * 
> FROM "datasets" 
> WHERE ("datasets"."id" IN (
> SELECT "fields"."dataset_id" 
> FROM "fields", "datasets" 
> WHERE (("fields"."field_name" ILIKE '%search_text%') 
> AND ("datasets"."latest" = 'T') ESCAPE '\'))); 
>
> That cross join is breaking the link between the two tables. If I edit 
> that by hand to check:
>
> SELECT * 
> FROM "datasets" 
> WHERE ("datasets"."id" IN (
> SELECT "datasets"."latest", "datasets"."id", "fields"."dataset_id" 
> FROM "fields", "datasets" 
> WHERE (("fields"."field_name" ILIKE '%search_text%') 
> AND ("datasets"."latest" = 'T') ESCAPE '\')));
>
> then I get rows like this:
>
>  latest  | id  | dataset_id 
> -+-+
>  T   | 134 |177
>  T   | 134 |177
>  T   | 134 |177
>  T   | 134 |180
>  T   | 134 |180
>  T   | 134 |180
>  T   | 158 |177
>  T   | 158 |177
>  T   | 158 |177
>
> What am I doing wrong?
>
> Cheers,
> David
>
>
>  From looking at the code, it seems like the current options are:
>
> 1. If parse_at_rest() gets a queries object that isn't a dict, the is 
> applied 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/2ac3a57b-ad0e-463d-845d-6d3d09494802%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.