|
From: <mic...@ya...> - 2004-06-13 03:17:55
|
Hi again guys!
I search through gmane and I can found a message can help me, so I
could do something, but I want to know if I do in the correct way, i
will show all the code:
#########################################
from sqlobject import *
conexao='postgres://localhost/teste'
class Person(SQLObject):
_connection=conexao
name=StringCol(length=100)
areas=RelatedJoin('Area')
def byArea(self, *elements):
connection=self._connection
in_clause=''
for i in elements:
in_clause+='%s, ' % i
result=connection.queryAll('''\
select
p.id
from person p
inner join area_person x on (x.person_id=p.id)
inner join area a on (x.area_id=a.id)
where
a.id in (%s)
group by
p.id;
''' % in_clause[:-2])
return IN(self.q.id, [x[0] for x in result])
byArea=classmethod(byArea)
class Area(SQLObject):
_connection=conexao
name=StringCol(length=100)
people=RelatedJoin('Person')
#########################################
so I can do:
[x.id for x in Person.select(Person.byArea(1, 2))]
I can return the selected object (but i prefer to run select manually,
so I can agregate another conditions) and I can receive the Area
instance, but for a test this code is ok I think...
Is there another way to run this query? Is this the best way to execute
queries, see that I can do, reater than execute a query, execute a
function...
thanks for the attention and sorry my poor english :)
=====
--
Michel Thadeu Sabchuk
Curitiba/PR
______________________________________________________________________
Participe da pesquisa global sobre o Yahoo! Mail:
http://br.surveys.yahoo.com/global_mail_survey_br
|