On Dec 3, 7:39 pm, Michael Bayer [EMAIL PROTECTED] wrote:
On Dec 3, 2008, at 1:26 PM, Guillaume wrote:
Hello,
is there a way with the ORM layer to have abstract base class like in
django ?
http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-
classes
sure, just pass along cls=MyBaseClass along to declarative_base().
You can also make your own metaclass if you wanted, and pass it in as
metaclass=MyMetaClass, or you can use the individual components within
declarative_base explicitly if you wanted to roll it yourself. This
is all in the docstrings for declarative.
So:
class A(object): pass
Base = declarative_base(cls=A)
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
b = B()
if isinstance(b, A):
print 'Success !'
completes successfully, great !
Another somehow related question is there any plan for declarative
base to support inheritance ala django ?
declarative supports all three of SQLA's table inheritance forms
fully.It pretty much happens automatically when you make a
subclass, and you just need to pass along polymorphic_on/
polymorphic_identity into __mapper_args__. If Django supported some
kind of inheritance scenario that we don't I'd be very interested to
see that :) .
The problem is not directly in the inheritance scenario, but rather
creating an association to an abstract class.
Let's say I have the following classes: CorporateCustomer and
PrivateCustomer inheriting from the abstract class Customer. On the
database side, I have the two following table: corporate_customer(id,
customer_info, corporate_info) and private_customer(id, customer_info,
private_info) (ids are generated by a unique sequence for all the
database). Now I have also Order objects associated to Customer
objects; the table looks like order(id, customer_id, order_info). Can
I map this scenario directly in SQLA without creating some dummy view
customer in the database ?
(Just checked how I did it with Django: with a set of ugly wrapper
method and views.)
Regards,
Guillaume
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---