Problem with ForeignKey

2 views
Skip to first unread message

kippertoffee

unread,
Aug 27, 2009, 5:59:34 PM8/27/09
to Autumn ORM
I have an account table, each account have one set of questions
(questionnaire website)
I have a question_set table, each set can belong to many accounts

class Set(Model):
questions = OneToMany('Question', field='question_set_id')
accounts = OneToMany('Account', field='question_set_id')
class Meta:
table = 'question_sets'

class Account(Model):
set = ForeignKey(Set, field='question_set_id')
class Meta:
table = 'accounts'

If if load an account using:
a = Account.get(1)

I am able to access the question set using:
a.set.name
a.set.id
etc

If I load multiple accounts, a la:
a = Account.get()[:10]

and iterate through each result, a.set is 'NoneType' object.
Attempting to call a field, e.g.:
print a.set.name

Throws the following error:

<type 'exceptions.AttributeError'> 'NoneType' object has no
attribute 'name'

Is this a bug or intentional, or am I getting it wrong?

Loving Autumn otherwise.

Cheers,
Pete
Reply all
Reply to author
Forward
0 new messages