YKdvd <davidobe...@gmail.com> wrote:

> I have model FruitCategories which uses the bidirectional adjacency list 
> pattern ("Node") from the documentation.  It is used to create a many-to-many 
> connection to a model, say, Fruit, with an association table ("fruits_cats"), 
> again vanilla like the docs.  This all works great.
> 
> I have other completely unrelated categories for unrelated entities in 
> similar many-to-many , and I though I could convert this into a generic 
> setup.   The categories table would become a general single-table polymorphic 
> inheritance setup, where FruitCategories might have polymorphic type 1, 
> HighwayCategories (which would map with a Highway entitiy) as 2, etc.  It 
> would seem the different category systems could share the same table.  
> 
> What I was wondering was if there would be a way to share the association 
> table in this setup, instead of having to create one for each new 
> category-entity combo?  Presumably a polymorphic association table isn't a 
> thing; could a polymorphic association object be set up, and each mapping 
> combo would create a subclass of Category and the association object.  I have 
> a hazy sense that declared_attr would have to be involved for one side of the 
> association and the Category children definition, but my head starts spinning 
> when I get this far.
> 

the polymorphic association thing has many variants, most of which are IMO
too complicated to be worth it, those are here at:
http://docs.sqlalchemy.org/en/rel_0_9/orm/examples.html#module-examples.generic_associations.

My preference is usually association table per association. The key here is,
“having to create each table” - what does that actually mean ? It seems like
it might mean, “I have to manually type out each Table”, but it doesn’t. The
automation we’re getting from SQLAlchemy automates the maintenance of many
individual association tables just as easily (in this case probably more
easily) as it would automate the maintenance of many rows within one big
table.

> Or am I going down a rabbit hole and should just create a new association 
> table for each mapping combo?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to