whoops...yeah, that is correct but you'll have to use trunk 5287 until
rc4 comes out (soon). It was stomping on top of 'inherit_condition'
within the declarative configuration.
On Nov 12, 2008, at 10:25 AM, tante wrote:
>
> Ok, I have it like this now:
> ---------------------------------
> class Comment(Object):
> """Allows commenting of any other entity in the server"""
> __tablename__= 'comments'
>
> uuid=Column(String(36),ForeignKey
> ('objects.uuid'),primary_key=True)
> __mapper_args__ = {'polymorphic_identity': 'comment',
> 'inherit_condition':uuid==Object.uuid}
>
> text=Column(String(),nullable=False)
> author=Column(String(),nullable=False)
> date=Column(AutoNowDateTime(),nullable=False)
> subject_id=Column(String(36),ForeignKey('objects.uuid'))
>
> def __repr__(self):
> return u"<Comment('%s','%s','%s')>" % (self.author,str
> (self.date),self.text[:20])
> -------------------------
>
> but I still get:
> ArgumentError: Can't determine join between 'objects' and 'comments';
> tables have more than one foreign key constraint relationship between
> them. Please specify the 'onclause' of this join explicitly.
>
>
>
>
>
> On Nov 12, 4:10 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
>> On Nov 12, 2008, at 9:42 AM, tante wrote:
>>
>>
>>
>>
>>
>>> I'm working on a system that has a Base class called Object. Many
>>> other classes inherit from this one class via joined table
>>> inheritance
>>> and it's working great. But now there's a problem: The subclass
>>> "Comment" does reference "Object" twice, once for the inheritance
>>> and
>>> once as a ForeignKey to mark which object the comment is about.
>>
>>> Code example:
>>> ----------------------------
>>> Base = declarative_base()
>>> class Object(Base):
>>> "Base class for all our Entities"
>>
>>> __tablename__= 'objects'
>>
>>> uuid=Column(String(36),primary_key=True)
>>> discriminator=Column(String(30), nullable=False)
>>
>>> __mapper_args__ = {'polymorphic_on': discriminator,
>>> 'polymorphic_identity': 'object'}
>>
>>> def __init__(self,*args,**kwargs):
>>> super(Object,self).__init__(*args,**kwargs)
>>> if not self.uuid:
>>> # create a random uuid
>>> self.uuid=str(uuid4())
>>
>>> def __repr__(self):
>>> return u"<Object('%s')>" % (self.uuid)
>>
>>> class Comment(Object):
>>> """Allows commenting of any other entity in the server"""
>>> __tablename__= 'comments'
>>> __mapper_args__ = {'polymorphic_identity': 'comment'}
>>
>>> uuid=Column(String(36),ForeignKey
>>> ('objects.uuid'),primary_key=True)
>>> text=Column(String(),nullable=False)
>>> author=Column(String(),nullable=False)
>>> date=Column(AutoNowDateTime(),nullable=False)
>>> subject_id=Column(String(36),ForeignKey('objects.uuid'))
>>
>>> def __repr__(self):
>>> return u"<Comment('%s','%s','%s')>" % (self.author,str
>>> (self.date),self.text[:20])
>>
>>> ------------------
>>> This leads to this error:
>>> #ArgumentError: Can't determine join between 'objects' and
>>> 'comments';
>>> #tables have more than one foreign key constraint relationship
>>> between
>>> them.
>>> #Please specify the 'onclause' of this join explicitly.
>>
>>> I tried to add __mapper_args__ to Comment like
>>> "inherit_condition=Comment.c.uuid==Object.c.uuid"
>>> but while I can get it to initialize, it won't let me query giving
>>> me
>>> this error:
>>> AttributeError: 'PropertyLoader' object has no attribute 'strategy'
>>
>>> How can I allow more than one reference between those Classes?
>>
>> strings aren't recognized for "inherit_condition", so do the dict lke
>> __mapper_args__ = {'inherit_condition':uuid==Object.uuid}, and place
>> __mapper_args__ in Comment after you define the "uuid" coumn.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---