Re: [web2py] Mulitple left join: unsupported query?

2012-03-13 Thread Richard Vézina
I think you need to use smartgrid for this kind of purpose, since smartgrid
si suppose to be the samething of grid but allow to manage more than one
table fk...

Richard

On Tue, Mar 13, 2012 at 3:39 AM, Johann Spies wrote:

> I have tried to translate this query:
>
> select A.id, A.surname, A.firstname, A.name, A.birthdate,
>A.race, A.gender, A.address, C.title as Journal, C.subject
> from  akb_authors A
> left join akb_authors_article_link B on
> (B.author = A.uuid)
> left join akb_articles D on (D.uuid = B.article)
> left join akb_journal C on (C.uuid = D.journal)
>
> where A.id in (507182, 788825)
>
> to DAL:
>
> query = db.akb_authors.id.belongs(ids)
> left = (db.akb_authors_article_link.on(db.akb_authors.uuid ==
> db.akb_authors_article_link.author),
> db.akb_articles.on(db.akb_articles.uuid ==
> db.akb_authors_article_link.article),
> db.akb_journal.on(db.akb_journal.uuid ==
> db.akb_articles.journal))
> fields = [db.akb_authors.id, db.akb_authors.surname,
> db.akb_authors.firstname,
>   db.akb_authors.name, db.akb_authors.birthdate,
> db.akb_authors.gender,
>   db.akb_authors.race, db.akb_authors.address,
> db.akb_journal.title,
>   db.akb_journal.subject ]
> headers = {'akb_journal.title': 'Journal'}
>
> form = SQLFORM.grid(query,
> fields=fields,
> maxtextlength = 100,
> deletable = False,
> editable = False,
> details = False,
> create = False,
> headers = headers,
> left = left,
> selectable = lambda ids: hanteer_verfyning(ids.id
> ),
> orderby = db.akb_authors.id)
>
> but it ignores all the fields that are not in the first table and prints
> 'unsupported query' on the screen:
>
> SELECT  akb_authors.id, akb_authors.surname, akb_authors.firstname,
> akb_authors.name, akb_authors.birthdate, akb_authors.gender,
> akb_authors.race, akb_authors.address
> FROM akb_authors
> LEFT JOIN akb_authors_article_link ON (akb_authors.uuid =
> akb_authors_article_link.author)
> LEFT JOIN akb_articles ON (akb_articles.uuid =
> akb_authors_article_link.article)
> LEFT JOIN akb_journal ON (akb_journal.uuid = akb_articles.journal)
> WHERE (akb_authors.id IN (507182,788825))
> ORDER BY akb_authors.id;
>
> So how do I get the grid to show the two fields in akb_journal for me?
>
> Regards
> Johann
>
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)
>
>


[web2py] Mulitple left join: unsupported query?

2012-03-13 Thread Johann Spies
I have tried to translate this query:

select A.id, A.surname, A.firstname, A.name, A.birthdate,
   A.race, A.gender, A.address, C.title as Journal, C.subject
from  akb_authors A
left join akb_authors_article_link B on
(B.author = A.uuid)
left join akb_articles D on (D.uuid = B.article)
left join akb_journal C on (C.uuid = D.journal)

where A.id in (507182, 788825)

to DAL:

query = db.akb_authors.id.belongs(ids)
left = (db.akb_authors_article_link.on(db.akb_authors.uuid ==
db.akb_authors_article_link.author),
db.akb_articles.on(db.akb_articles.uuid ==
db.akb_authors_article_link.article),
db.akb_journal.on(db.akb_journal.uuid ==
db.akb_articles.journal))
fields = [db.akb_authors.id, db.akb_authors.surname,
db.akb_authors.firstname,
  db.akb_authors.name, db.akb_authors.birthdate,
db.akb_authors.gender,
  db.akb_authors.race, db.akb_authors.address,
db.akb_journal.title,
  db.akb_journal.subject ]
headers = {'akb_journal.title': 'Journal'}

form = SQLFORM.grid(query,
fields=fields,
maxtextlength = 100,
deletable = False,
editable = False,
details = False,
create = False,
headers = headers,
left = left,
selectable = lambda ids: hanteer_verfyning(ids.id),
orderby = db.akb_authors.id)

but it ignores all the fields that are not in the first table and prints
'unsupported query' on the screen:

SELECT  akb_authors.id, akb_authors.surname, akb_authors.firstname,
akb_authors.name, akb_authors.birthdate, akb_authors.gender,
akb_authors.race, akb_authors.address
FROM akb_authors
LEFT JOIN akb_authors_article_link ON (akb_authors.uuid =
akb_authors_article_link.author)
LEFT JOIN akb_articles ON (akb_articles.uuid =
akb_authors_article_link.article)
LEFT JOIN akb_journal ON (akb_journal.uuid = akb_articles.journal)
WHERE (akb_authors.id IN (507182,788825))
ORDER BY akb_authors.id;

So how do I get the grid to show the two fields in akb_journal for me?

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)