I was not using declarative_base before. I used the normal method first
encountered in the SQLAlchemy book. I tried the example in the book and
applied to my problem and it worked.
This is the first time, I am trying out with declarative base.
I will now look into your script.
On Tue, Nov 4, 2008 at 5:13 PM, Michael Bayer <[EMAIL PROTECTED]>wrote:
> also, I wonder how the way you were doing it before, with composite, was
> actually working out ? It wasn't intended to hold "half" of a primary key
> like that which is probably why I warned against it, but if its working for
> you, there's no reason not to use it.
> I.e. with declarative just put the Column objects inside the composite:
>
> class User(Base):
>
> __tablename__ = 'user'
>
> house_address_id = Column('house_address', Integer,
> ForeignKey('address.id'))
> office_address_id = Column('office_address', Integer,
> ForeignKey('address.id'))
> house_address = relation(Address,
> primaryjoin=house_address_id==Address.id)
> office_address = relation(Address,
> primaryjoin=office_address_id==Address.id)
> comp = composite(Comp, Column('id', Integer, primary_key=True,
> autoincrement=True), Column('name', CHAR))
>
>
>
> On Nov 4, 2008, at 7:29 PM, Ritesh Nadhani wrote:
>
> Unfortunately, it still gives me an error.
>
> http://paste.pocoo.org/show/90191
>
> Did I miss something?
>
> PS: I added the __get__ method just for the fun of it, I have no idea what
> it does. Looking at the docs:
> http://www.sqlalchemy.org/docs/04/sqlalchemy_orm_interfaces.html#docstrings_sqlalchemy.orm.interfaces_PropComparator,
> seems that I have to implement other methods but I am not sure which one.
>
> Any help is appreciated.
>
> On Mon, Oct 27, 2008 at 7:45 AM, Michael Bayer <[EMAIL PROTECTED]>wrote:
>
>>
>> theres a "bug" in that the error message is misleading, but in fact a
>> composite property owns the columns within it which cannot be mapped
>> separately, so to make that "work" you'd need to say:
>>
>> class User(Base):
>>
>> __tablename__ = 'user'
>>
>> house_address_id = Column('house_address', Integer,
>> ForeignKey('address.id'))
>> office_address_id = Column('office_address', Integer,
>> ForeignKey('address.id'))
>> house_address = relation(Address,
>> primaryjoin=house_address_id==Address.id)
>> office_address = relation(Address,
>> primaryjoin=office_address_id==Address.id)
>> comp = composite(Comp, Column('id', Integer, primary_key=True,
>> autoincrement=True), Column('name', CHAR))
>>
>> but the way you're using Comp isn't going to work in any case; you're
>> actually looking for comparable_property() here:
>>
>> class MyComparator(sqlalchemy.orm.interfaces.PropComparator):
>> def __eq__(self, other):
>> return self.comp == other.comp
>>
>> class User(Base):
>>
>> __tablename__ = 'user'
>>
>> id = Column('id', Integer, primary_key=True, autoincrement=True)
>> name = Column('name', CHAR)
>> house_address_id = Column('house_address', Integer,
>> ForeignKey('address.id'))
>> office_address_id = Column('office_address', Integer,
>> ForeignKey('address.id'))
>> house_address = relation(Address,
>> primaryjoin=house_address_id==Address.id)
>> office_address = relation(Address,
>> primaryjoin=office_address_id==Address.id)
>>
>> @property
>> def comp(self):
>> return self.id + self.name
>>
>> comp = comparable_property(MyComparator)
>>
>>
>> On Oct 27, 2008, at 9:22 AM, riteshn wrote:
>>
>> >
>> > Hello all
>> >
>> > New to SQLAlchemy and ORM and loving it. I am trying to use the
>> > declarative base extension with composite column.
>> >
>> > I have two very simple tables - user and address.
>> >
>> > My code at: http://python.pastebin.com/m6e032164 works without any
>> > problem.
>> >
>> > I am trying to put the same thing using declarative base:
>> > http://python.pastebin.com/m1a05e5c0 and it throws me the error.
>> >
>> > Any ideas?
>> >
>> > >
>>
>>
>>
>>
>
>
> --
> Ritesh
> http://www.riteshn.com
>
>
>
>
>
> >
>
--
Ritesh
http://www.riteshn.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---