Werner F. Bruhin schrieb:
> Robert,
> 
> robert rottermann wrote:
> ...
>> however I would like to change the assignMyselfToCompany method in a way 
>> that I
>> could achieve the same with:
>>
>> product = tblProducts_kl()
>> product.assignMyselfToCompany(company_id)
>>   
> Unless you do some more things in your assignMyselfToCompany I think you 
> can just do:
> 
> product = tblProducts_kl()
> company.productRelation = product
> or probably more likely this as I assume a company can have more then 
> one product.
> company.productRelation.append(product)
> 
> And SA doe the magic for you.
> 
> See:
> http://www.sqlalchemy.org/docs/05/ormtutorial.html#adding-new-objects
> 
> particularly Working with Related Objects
> 
> Hope this helps
> Werner
thanks werner,

this is exactly what I would like to do *within* the instance by calling one of
its methods.
the reason is, that there are many different product-types and each one has its
own class that uses a common mixin class.
each such class is associated with a different table and therefore an other
relation.
so the compay-class has in fact many relations and I want to avoid that I have
to know to what relation I have to add the product.


class Products_hlwdHandler(ProductMixin):
    tblClass = tblProducts_hlwd
    FIELDS = PRODUCTS_HLWD_FIELDS
    COMPANY_ID = 'company_id'
    COMPANY_FIELD = 'related_hlwdProducts'

class Products_klHandler(ProductMixin):
    tblClass = tblProducts_kl
    FIELDS = PRODUCTS_KL_FIELDS
    COMPANY_ID = 'company_id'
    COMPANY_FIELD = 'related_klProducts'
....

as you can see. each such class knows its relation within the companyCL class
definiton (for Products_hlwdHandler it is 'related_hlwdProducts') to which it
could associate itself. If only it knew "its" id ..

robert


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to