I really really need to know what's wrong with SA and solve it. Please
give me a hand.
I couldn't make relationship between classes in expose method of
controller but nothing wrong in tg-admin shell.

Here's my classes in model (I use TurboEntity):

class Artist(Entity):
    name = Column(Unicode(16), nullable=False, unique=True)
    songs = OneToMany("Song")

class Song(Entity):
    name = Column(Unicode(16), nullable=False)
    artist = ManyToOne("Artist")

And here's my method in controller:

@expose()
def save(self):
    artist = Artist.get(1)
    song = Song(name="Song Name", artist=artist)

    return dict()

Okay. Here's the problem I met. There should be relationship between
Artist and Song, but they don't. Be more clear, I give an example if I
run something in tg-admin shell:

>>> Song.select()[-1]
<Song entity at 0x1a29990>
>>> Song.select()[-1].id
1
>>> Song.select()[-1].artist
>>> Song.select()[-1].artist.name
Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'name'
>>>

But, If I run this in tg-admin shell, everything is correct:

>>> artist = Artist.get(1)
>>> song = Song(name="Song Name", artist=artist)
>>> session.flush()
>>> Song.select()[-1]
<Song entity at 0x1a290d0>
>>> Song.select()[-1].id
2
>>> Song.select()[-1].artist
<Artist entity at 0x1a29610>
>>> Song.select()[-1].artist.name
u'McFly'
>>>

See? Everything is correct in tg-admin shell but isn't in expose
method. I don't know if I missed something, but I really need to solve
this problem. Any help would be appreciated. Thanks.


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