On Apr 4, 12:47 pm, annet <[email protected]> wrote:
> I have been exploring the DAL examples which are under documentation
> on the website.
>
> I have got the following model:
>
> db.define_table('person',
>     db.Field('name','string'))
>
> db.define_table('dog',
>     db.Field('name'))
>
> db.define_table('friendship',
>     db.Field('person',db.person),
>     db.Field('dog',db.dog))
>
> in which I inserted a couple of persons and dogs.
Do you have these? They would make input easier:
db.friendship.person.requires=IS_IN_DB(db,'person.id','%(name)s')
db.friendship.dog.requires=IS_IN_DB(db,'dog.id','%(name)s')
>
> The Reference Fields Inner Joins example is working, however, I don't
> get the Left Outer Joins example to work.
>
> In my controller I have got:
>
> def myouter():
>     query=(db.person.id>0)
>     friends=(db.person.id==db.friendship.person)&
> (db.dog.id==db.friendship.dog)
>     rows=db(query).select(db.person.name,db.dog.name,left=db.dog.on
> (friends))
>     return dict(rows=rows)
>
> and in the view:
>
> {{extend 'layout.html'}}
>
> {{for row in rows:}}
> {{=row.person.name}}
> is friend of
> {{=row.dog.name or nobody}}
> <br />
>
> When I expose myouter I got the following error ticket:
>
> OperationalError: no such column: friendship.dog
If you display db._lastsql
'SELECT person.name, dog.name FROM person LEFT JOIN dog ON
(person.id=friendship.person AND dog.id=friendship.dog) WHERE
person.id>0;'
you will see that you don't have the required friendship.id anywhere

What you want is probably;
rowsr=db(db.person.id>0).select(db.person.name,db.dog.name,left=
[db.friendship.
on(db.friendship.person==db.person.id),db.dog.on
(db.friendship.dog==db.dog.id)])

>
> Does one one of you know why this ticket is issued?
>
> Kind regards,
>
> Annet
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to