Hi all,

I'm new to sqlalchemy, I'm using 0.5rc4 and I want to map a many to
many relation with extra fields on the association table using
declarative way, I read

http://www.sqlalchemy.org/docs/05/mappers.html#association-object

but there there is the non declarative way, here is what I have in my
mappig:

"""
access_type=0 -> read only
access_type=1 -> read write
"""

m2m_users_shares=Table('m2m_users_share',metadata,
        Column('user_id',Integer,ForeignKey('samba_users.id',
                        onupdate="CASCADE", ondelete="CASCADE",nullable=False)),
        Column('share_id',Integer,ForeignKey('samba_shares.id',
                        onupdate="CASCADE", ondelete="CASCADE",nullable=False)),
        Column('access_type',SmallInteger,default=0,nullable=False)
)

class SambaUsers(DeclarativeBase):
        __tablename__='samba_users'
        id=Column(Integer,primary_key=True)
        username=Column(Unicode(80),nullable=False,unique=True,index=True)
        password=Column(Unicode(255),nullable=False)
        attivo=Column(Boolean(),default=True,nullable=False)
        creato = Column(DateTime)
        modificato = Column(DateTime, default=datetime.now)

        def __init__(self,username,password):
                self.creato=datetime.now()
                self.username=username
                self.password=password

        def __repr__(self):
                return '<SambaUser: username="%s">' % (self.username)


class SambaShares(DeclarativeBase):
        __tablename__='samba_shares'
        id=Column(Integer,primary_key=True)
        nome=Column(Unicode(255),nullable=False,unique=True,index=True)
        path=Column(Unicode(255),nullable=False)
        creato = Column(DateTime)
        modificato = Column(DateTime, default=datetime.now)

        #users = relation('SambaUsers', secondary=m2m_users_shares,
backref='shareusers')
        users = relation('SambaUsers', backref='shareusers')


        def __init__(self,nome,path):
                self.creato=datetime.now()
                self.nome=nome
                self.path=path

        def __repr__(self):
                return '<SambaShare: nome="%s", path="%s">' % (
                        self.nome,self.path)

in samba share I removed "secondary" but now how sqlalchemy know about
m2m relation?

thanks
drakkan

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