On Wed, Jul 2, 2008 at 1:54 PM, jrpfinch <[EMAIL PROTECTED]> wrote:

>
>
>
> On 2 Jul, 19:45, "Kevin Horn" <[EMAIL PROTECTED]> wrote:
> > On Wed, Jul 2, 2008 at 1:39 PM, jrpfinch <[EMAIL PROTECTED]> wrote:
> >
> > > Thanks Kevin, I will look into SQLAlchemy.
> >
> > > Unfortunately, b.ne_ems_id.ems_name does not work I just get the
> > > following:
> >
> > >  Traceback (most recent call last):
> > >  File "<console>", line 1, in ?
> > > AttributeError: 'int' object has no attribute 'ems_name'
> >
> > > If it matters, I am using pymssql
> >
> > > On 2 Jul, 19:27, "Kevin Horn" <[EMAIL PROTECTED]> wrote:
> > > > On Wed, Jul 2, 2008 at 12:21 PM, jrpfinch <[EMAIL PROTECTED]>
> wrote:
> >
> > > > > Hi I'm new at TurboGears and am getting slightly confused/lost by
> the
> > > > > SQLObject docs.
> >
> > > > > I would be grateful if somebody could explain what the easiest way
> to
> > > > > get the ems_name of a record in Ne_live is.
> >
> > > > > b=Ne_live.get(4)
> > > > > b.Ems_live.ems_name ?????????
> > > > > Traceback (most recent call last):
> > > > >  File "<console>", line 1, in ?
> > > > > AttributeError: 'Ne_live' object has no attribute 'Ems_live'
> > > > >  c.ne_ems_id.ems_name ?????
> > > > > Traceback (most recent call last):
> > > > >  File "<console>", line 1, in ?
> > > > > AttributeError: 'int' object has no attribute 'ems_name'
> >
> > > > > class Ems_live(SQLObject):
> > > > >    class sqlmeta:
> > > > >        idName = "ems_id"
> > > > >    ems_name = StringCol()
> > > > >    ems_sm_time = DateTimeCol()
> > > > >    ems_sm_code = IntCol()
> >
> > > > > class Ne_live(SQLObject):
> > > > >    class sqlmeta:
> > > > >        idName = "ne_id"
> > > > >    ne_ems_id = ForeignKey("Ems_live")
> > > > >    ne_name = StringCol()
> >
> > > > > Many thanks
> >
> > > > > Jon
> >
> > > > First, if you're just getting started with TG, you might really want
> to
> > > > consider using SQLAlchemy rather than SQLObject.  I totally
> understand if
> > > > you want to take the learning curve in small doses, though.
> >
> > > > Second, I think (based on a hazy memory of SQLObject), that you want
> > > > something like:
> >
> > > > b=Ne_live.get(4)
> > > > b.ne_ems_id.ems_name
> >
> > > > You might want to check out this tutorial for more info:
> > >http://exogen.case.edu/turbogears.html
> >
> > > > It's a little outdated, but it should give you an idea.
> >
> > > > Good luck!
> >
> > > > Kevin Horn
> >
> > Hmmm, you might also try changing:
> >
> > ne_ems_id = ForeignKey("Ems_live")
> >
> > to:
> >
> > ne_ems = ForeignKey("Ems_live")
> >
> > or something similar...I remember that SQLObject has some kind of
> implicit
> > id column naming stuff that caused me issues in the past.
> > You may have problems if the column name in your SQLObject is the same as
> > the auto-generated column name in your DB table, but
> > I really can't recall whether that would affect you in this particular
> case.
> >
> > Kevin Horn
>
> Unfortunately I can't change ne_ems_id to ne_ems because I have not
> control over the structure of the underlying database
>

What I'm saying is that the reference in your SQLObject should be named
something _other_ than what the id column is named in your database.
SQLObject then creates what it thinks should be the name of the column in
the database to use internally.  So the

So if you have something like:(taken from the tutorial I referenced
earlier):

class User(SQLObject):
>     email = StringCol(alternateID=True)
>     lists = MultipleJoin('List')
>
> class List(SQLObject):
>     title = UnicodeCol(notNone=True)
>     user = ForeignKey('User')
>
> then you should be able to access it by:

listObject = List.get(some_id)
listObject.user.email

but in the actual database, the column name will be something like"user_id"
or "userID".

If you are dealing with a legacy database then I _really_ suggest that you
go with SQLAlchemy.  It gives you much better control over this sort of
thing.  SQLObject tries to do too much "automagically" in this area.

Kevin Horn

--~--~---------~--~----~------------~-------~--~----~
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