Am Dienstag, 9. Januar 2007 17:01 schrieb Michael Bayer: > we do have an extension called "associationproxy" that is used for > something similar with association objects...it may give you some > ideas on how to proxy attributes across. i dont think you should > approach the idea of "adding individual properties" as "quite > complicated"...for example, you could write a function that adds all > the "Address" properties to the "Person" class en-masse: > > for key in class_mapper(Address).props: > setattr(Person, key, property(...some getter function...)) > > if you come up with something generally useful in that idiom, you can > post to the SA wiki or we can even make another extension if its > really of general use.
At first, thanks for your quick answer. My basic idea was to maintain the abstraction between the data model and the actual object. So the ideal place to specify such things would be in the mapper. To my mind, some "magic" with the properties could do it, e.g. like this: mapper(Person, person_table, properties = dict( address=relation(Address, secondary=r_pers_addrid_table, proxy_relation_attributes=True)) In case "proxy_relation_attributes" is set to "True", all columns (except the foreign keys which are obsolete) are made accessible through the relation - very simple syntax. Correct me if I'm wrong, but many to many relations are normally done this way: table1 <---> association_table <---> table2 table1 has a one to many relation to association_table and table2 has also a one to many relation to association_table. From the perpective of table1, it should therefore in any case be possible to locate association/relation attributes along with the attributes of table2 (and the same in the other direction). The only problem could be name clashes, which could probably be handled in some way (e.g. raise an exception or prefix them). This may also obsolete the "associationproxy" - but maybe I don't fully understand its concepts. This solution would make it possible to alter the data model, e.g. make a one to many relation from a many to many relation, e.g.: table1 <-----> table2 without having to touch the object representing the function - the only thing I'd have to change is the mapper. I have no clue how I would implement such a relation property as I'm very new to SA, perhaps it's impossible for some reason. However, I think putting attributes in association tables is a common pattern in data models, so this could be of use for many SA users. What do you think of this idea? Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---