Sorry if I’m missing something basic and/or pretty obvious but I don’t know how 
to model collections of different types/classes.

For example, let’s say I have these base types/classes:

class Chicken(Base):
    __tablename__ = ‘chicken'
    id   = Column(Integer, primary_key=True)
    name = Column(Unicode(50))

class Cow(Base):
    __tablename__ = ‘cow'
    id   = Column(Integer, primary_key=True)
    name = Column(Unicode(50))

The problem is Old McDonald has multiple barns! So we have:

class Barn(Base):
    __tablename__ = ‘barn'
    id   = Column(Integer, primary_key=True)
    name = Column(Unicode(50))

How do we keep collections of “chicken”s and “cow”s in “barn”s?

Let’s say he creates a “Barn 1” row in “barn”. 10 rows from “chicken”s and 10 
rows from “cow”s need to associate to the “Barn 1” row in “barn”. And then 
later another set of chickens and cows will need to be associated with a “Barn 
2".

So a “barn” row is our container that holds our collections.

Also, I think what’s causing some confusion is that a “chicken" or “cow" row 
can be associated with more than 1 “barn" at a time. They’re picky that way and 
like a change of scenery from time to time.

So maybe given the fact that “chicken” or “cow” rows can be associated more 
than 1 “barn” at a time, does this mean I’ll need to setup a many-to-many 
relation? And make sure I get the “relationship” call configured correctly on 
those referring columns?

Thanks for any help or guidance.

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