Hi Gaetan,
Thanks. I guess I just have to pass it a tuple:
def Print(rowlist, collist):
for r in rowlist:
for t in r:
for c in collist:
try:
print t.__dict__[c.name]
break
except:
pass
...
rows = session.query(History,User).join(History.UserId).all()
cols = list()
cols.append(History.table.columns.Sequence)
cols.append(User.table.columns.Name)
Print(rows,cols)
Thanks again,
George
On Mar 9, 7:08 pm, Gaetan de Menten <[email protected]> wrote:
> On Sun, Mar 8, 2009 at 14:56, gvv <[email protected]> wrote:
>
> > How do you pass a ManyToOne property to a function ?
>
> > I have a function that selectively prints columns from a given row:
>
> > def Print(rowlist, collist):
> > for r in rowlist:
> > for c in collist:
> > print r.__dict__[c.name]
>
> > using the following Entities:
>
> > class User(Entity):
> > using_options(tablename="user")
> > UserId = Field(String(16))
> > Name = Field(String(64))
>
> > class History(Entity):
> > using_options(tablename="history")
> > Sequence = Field(Integer)
> > UserId = ManyToOne("User")
>
> > called from main as follows:
> > ....
> > rows = History.query.all()
> > cols = list()
> > cols.append(History.table.columns.Sequence)
> > cols.append(History.table.columns.UserId_id) # ???? I need to print
> > User.Name
>
> That won't work because the name of the user is not stored in the
> History table, so no column exist in that table. At best, you can get
> the numerical id of the User.
>
> > Print(rows,cols)
>
> > given the following works:
> > for r in rows:
> > print r.Sequence, r.UserId.Name
> > I think passing a column property to function will also work. I just
> > dont know how.
>
> You should rather filter the data directly in the query, and use a join.
>
> Something like:
> session.query(History).join(History.UserId)...
>
> See:http://www.sqlalchemy.org/docs/05/ormtutorial.html#querying-with-joins
>
> --
> Gaëtan de Mentenhttp://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---