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.