First of all, thank you very much for answering my questions...
so, I did what you told me and this is what happened:
(changed userid -> owner and removed tg_pet)
// ------------------------------------
[EMAIL PROTECTED]:~/tmp/singleJoin$ tg-admin shell
Python 2.4.3 (#2, Oct 6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(CustomShell)
>>> u = User.get(1)
>>> Pet(name='something',surname='somethingelse', color='black',owner=u)
<Pet 1L name=u'something' surname=u'somethingelse' color=u'black'
ownerID=1L>
>>> p =Pet(name='something',surname='somethingelse', color='black',owner=u)
>>> p
<Pet 2L name=u'something' surname=u'somethingelse' color=u'black'
ownerID=1L>
>>> p
<Pet 2L name=u'something' surname=u'somethingelse' color=u'black'
ownerID=1L>
//
-----------------------------------------------------------------------------
but then, when I try to use catwalk...I cannot select neither the user
nor the Pet...
this is what the logs says:
when I select Pet.
// -----------------------------
"/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/mysql/mysqlconnection.py",
line 73, in _executeRetry
myquery = unicode(query, self.encoding)
TypeError: decoding Unicode is not supported
// -----------------------------
when I select User
// --------------------------------
raise AttributeError("%s instance has no attribute '%s'" %
(self.soClass.__name__, attr))
AttributeError: Pet instance has no attribute 'tgID'
// ----------------------
really lost. I cannot believe that this doesn't happen to you.
I'm using Kubuntu Dapper...does it matter?
Muchas Gracias!
On Nov 1, 3:29 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> On 11/1/06, miya <[EMAIL PROTECTED]> wrote:
>
> > Ok. Did that and it doesn't work either...
>
> > Now it says ...
>
> > raise AttributeError("%s instance has no attribute '%s'" %
> > (self.soClass.__name__, attr))
> > AttributeError: Pet instance has no attribute 'tgID'
> > Request Headers:
> > COOKIE: tg-visit=07ad5cd8a247b08a9df1a3d2acdcebd944aaa657umm catwalk
> > issues with identity are supposed to be solve.
>
> can you please try that with the console this seems to be a catwalk issue.
>
> $ tg-admin shell
>
> >>> u=User.get(1) #ur first user
> >>> Pet(name='something',surname='somethingelse',color='black',userid=u)also
> >>> you don't need the sqlmeta for pet that is there because of the
> comment in the User table, also the tg_* tables are "reserved" for
> internal use although currently only those 3 exists.
>
> and why userid, why not something more OOP like owner?
>
> > The model.py
> > //
> > ------------------------------------------------------------------------------------
>
> > class Pet(SQLObject):
> > class sqlmeta:
> > table = 'tg_pet'
> > name = UnicodeCol(length = 40)
> > surname = UnicodeCol(length = 40)
> > color = UnicodeCol(length = 40)
> > userid = ForeignKey("User")
>
> > class User(SQLObject):
> > """
> > Reasonably basic User definition. Probably would want additional
> > attributes.
> > """
> > # names like "Group", "Order" and "User" are reserved words in SQL
> > # so we set the name to something safe for SQL
> > class sqlmeta:
> > table = "tg_user"
>
> > user_name = UnicodeCol(length=16, alternateID=True,
> > alternateMethodName="by_user_name")
> > email_address = UnicodeCol(length=255, alternateID=True,
> > alternateMethodName="by_email_address")
> > display_name = UnicodeCol(length=255)
> > password = UnicodeCol(length=40)
> > created = DateTimeCol(default=datetime.now)
>
> > myPet = SingleJoin("Pet")
>
> > # groups this user belongs to
> > groups = RelatedJoin("Group", intermediateTable="user_group",
> > joinColumn="user_id", otherColumn="group_id")
>
> > //
> > ------------------------------------------------------------------------------------
>
> > I'm using mysql and the latest version of TG.
>
> > It doesn't work with MultipleJoin either... I tried relatedJoin and it
> > worked.
>
> > I'm really _really_ lost.
> > <desperately crying for help ;(>
>
> > On Nov 1, 12:55 pm, "Jorge Vargas" <[EMAIL PROTECTED]> wrote:
> > > everything seems ok expect this line
>
> > > myPet = SingleJoin("Pet", joinColumn = "user_id")
>
> > > the default join col is user_id, maybe Catwalk is doing something
> > > wrong like trying to set it twice, can you try without the joinColumn
> > > param
>
> > > On 11/1/06, miya <[EMAIL PROTECTED]> wrote:
>
> > > > Hello people!, I'm having trouble with singlejoin and SO. Nothing too
> > > > complicated, just doing an example to see how to use TG.
>
> > > > The example that fails on me is this one...
> > > > The idea is that One user can have One Pet. So it's a one-to-one
> > > > relationship. As far as I know its a singleJoin.
>
> > > > The thing is that when I'm using catwalk to insert my data, suddendly,
> > > > the insert user tab stops responding...I look at the logs and this is
> > > > what I see.
>
> > > > //
> > > > ---------------------------------------------------------------------------------------------
>
> > > > 2006-11-01 10:18:40,329 turbogears.identity INFO Identity is
> > > > available...
> > > > 127.0.0.1 - - [01/Nov/2006:10:18:40] "GET
> > > > /catwalk/browse?object_name=User HTTP/1.1" 302 161 "" "Mozilla/5.0
> > > > (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060921
> > > > Ubuntu/dapper-security Firefox/1.5.0.7"
> > > > 2006-11-01 10:18:40,342 turbogears.identity DEBUG Retrieving identity
> > > > for visit: 68e36dab0194b37f098561b44aad3285d637c9d6
> > > > 2006-11-01 10:18:40,343 turbogears.identity INFO Identity is
> > > > available...
> > > > 2006-11-01 10:18:40,344 turbogears.database DEBUG Starting SQLObject
> > > > transaction
> > > > 2006-11-01 10:18:40,346 turbogears.controllers DEBUG Calling <function
> > > > index at 0xb745d614> with *((<turbogears.toolbox.catwalk.browse.Browse
> > > > object at 0xb7467e6c>, u'User')), **({'start': 0, 'filters': '',
> > > > 'context': '', 'page_size': 10})
> > > > 01/Nov/2006:10:18:40 HTTP INFO Page handler: <bound method Browse.index
> > > > of <turbogears.toolbox.catwalk.browse.Browse object at 0xb7467e6c>>
> > > > Traceback (most recent call last):
> > > > File
> > > > "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
> > > > line 105, in _run
> > > > self.main()
> > > > File
> > > > "/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
> > > > line 254, in main
> > > > body = page_handler(*virtual_path, **self.params)
> > > > File "<string>", line 3, in index
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
> > > > line 326, in expose
> > > > output = database.run_with_transaction(
> > > > File "<string>", line 5, in run_with_transaction
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/database.py",
> > > > line 246, in so_rwt
> > > > retval = func(*args, **kw)
> > > > File "<string>", line 5, in _expose
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
> > > > line 343, in <lambda>
> > > > mapping, fragment, args, kw)))
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
> > > > line 367, in _execute_func
> > > > output = errorhandling.try_call(func, *args, **kw)
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/errorhandling.py",
> > > > line 71, in try_call
> > > > return func(self, *args, **kw)
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> > > > line 24, in index
> > > > total,rows =
> > > > self.rows_for_model(object_name,start,page_size,filters)
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> > > > line 124, in rows_for_model
> > > > relations = self.relation_values(object_name,rows)
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> > > > line 166, in relation_values
> > > > where=AND(
> > > > File
> > > > "/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> > > > line 196, in join_foreign_key
> > > > return getattr(column.otherClass.q,foreign_key)
> > > > File
> > > > "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/sqlbuilder.py",
> > > > line 356, in __getattr__
> > > > raise AttributeError("%s instance has no attribute '%s'" %
> > > > (self.soClass.__name__, attr))
> > > > AttributeError: Pet instance has no attribute 'userID'
> > > > Request Headers:
> > > > COOKIE: tg-visit=68e36dab0194b37f098561b44aad3285d637c9d6
> > > > Content-Length:
> > > > ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> > > > USER-AGENT: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7)
> > > > Gecko/20060921 Ubuntu/dapper-security Firefox/1.5.0.7
> > > > CONNECTION: keep-alive
> > > > HOST: localhost:7654
> > > > ACCEPT:
> > > > text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> > > > Remote-Addr: 127.0.0.1
> > > > ACCEPT-LANGUAGE: en-us,en;q=0.5
> > > > Content-Type:
> > > > Remote-Host: 127.0.0.1
> > > > ACCEPT-ENCODING: gzip,deflate
> > > > KEEP-ALIVE: 300
> > > > 127.0.0.1 - - [01/Nov/2006:10:18:40] "GET
> > > > /catwalk/browse/?object_name=User HTTP/1.1" 500 3182 "" "Mozilla/5.0
> > > > (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060921
> > > > Ubuntu/dapper-security Firefox/1.5.0.7"
> > > > //
> > > > ---------------------------------------------------------------------------------------------
>
> > > > the most important thing that I can see is this line:
>
> > > > ################
>
> > > > raise AttributeError("%s instance has no attribute '%s'" %
> > > > (self.soClass.__name__, attr))
> > > > AttributeError: Pet instance has no attribute 'userID'
>
> > > > ################
>
> > > > and I just don't get it... :(
>
> > > > models.py
>
> > > > //
> > > > ------------------------------------------------------------------------------------------------------
>
> > > > from datetime import datetime
>
> > > > from sqlobject import *
>
> > > > from turbogears import identity
> > > > from turbogears.database import PackageHub
>
> > > > hub = PackageHub("singlejoin")
> > > > __connection__ = hub
>
> > > > # class YourDataClass(SQLObject):
> > > > # pass
>
> > > > class Pet(SQLObject):
> > > > class sqlmeta:
> > > > table = 'tg_pet'
> > > > name = UnicodeCol(length = 40)
> > > > surname = UnicodeCol(length = 40)
> > > > color = UnicodeCol(length = 40)
> > > > userid = ForeignKey("User")
>
> > > > class User(SQLObject):
> > > > """
> > > > Reasonably basic User definition. Probably would want additional
> > > > attributes.
> > > > """
> > > > # names like "Group", "Order" and "User" are reserved words in SQL
> > > > # so we set the name to something safe for SQL
> > > > class sqlmeta:
> > > > table = "tg_user"
>
> > > > user_name = UnicodeCol(length=16, alternateID=True,
> > > > alternateMethodName="by_user_name")
> > > > email_address = UnicodeCol(length=255, alternateID=True,
> > > > alternateMethodName="by_email_address")
> > > > display_name = UnicodeCol(length=255)
> > > > password = UnicodeCol(length=40)
> > > > created = DateTimeCol(default=datetime.now)
>
> > > > myPet = SingleJoin("Pet", joinColumn = "user_id")
>
> > > > # groups this user belongs to
> > > > groups =...
>
> read more ยป
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---