On Thursday 25 January 2007 11:37, Raju Subban wrote:
> Hi,
> I am looking for a call that would return a instance of object when I query
> with the id (primary key of  the table)
> Don't know what to use.
> If I have a table say
>
> class Process(SQLObject):
>     process = StringCol(length=50, alternateID=True)
>     def __str__(self):
>         return "%s" % (process)
>
> command
>
> >>>p1=Process.byProcess("<aname>")
>
> will give me
>
> >>>type(p1)
>
> <class 'eup.model.Process'>
>
> I tried
>
> >>>p2= Process.selectBy(id=1)
>
> This gives
>
> >>> type(p2)
>
> <class 'sqlobject.sresults.SelectResults'>
>
> >>>print p2
>
> SELECT process.id, process.diameter <blah> FROM process WHERE id = 1
>
> Then if I go for an iterator, its looks ok
>
> >>>for pr in p2:
> >>>         print pr
>
> is ok
> pr is a object of type eup.model.Process
>
> Is there a way I can skip the for loop?

Several. First of all, if you really have an id and just want to get the 
object for it, use get.

p2 = Process.get(id)

If you have a query and know the number of results, you can directly index it

p2 = Process.selectBy(id=1)[0]

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to