[sqlalchemy] Re: Abstract base class

2008-12-04 Thread Guillaume



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



[sqlalchemy] Re: Abstract base class

2008-12-04 Thread Guillaume


 sure this is called concrete table inheritance.   Though when you  
 make a relation to Order, you need to declare these separately for  
 CorporateCustomer and PrivateCustomer since the connection from a  
 relational perspective is different.   When concrete inheritance uses  
 an abc, it maps to a union of the subtables so that you can load  
 polymorphically.  To do that with declarative you'd also have to  
 create the Table objects separately and pull them in to each class  
 using __table__.

 So with those limitations, if it were me I wouldn't use the concrete  
 inheritance feature unless i needed to load Customer objects  
 generically, I'd instead use Customer as a mixin class stated after  
 the declarative base class.

Which prety much means no generic query for Customer objects ...

I'll go down the concrete inheritance path and create a couple of
views for handling my abstract classes.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Abstract base class

2008-12-03 Thread Guillaume

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

Another somehow related question is there any plan for declarative
base to support inheritance ala django ?

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