Hi to all and thanks in advance for any help!
I'm trying to set up a DB with a many-to-many relation containing an
attribute in the 'secondary' table. Let me post some code to be more
clear

//begin code
sottoconti_ce_proporzionali_ce_per_attivita = Table
('sottoconti_ce_proporzionali_ce_per_attivita', metadata,
    Column('sottoconto_id', Integer, ForeignKey('sottoconto_ce.id',
onupdate="CASCADE", ondelete="CASCADE"), primary_key=True),
    Column('attivita_id', Integer, ForeignKey('attivita.id',
onupdate="CASCADE", ondelete="CASCADE"), primary_key=True),
    Column('sottoconto_proporzionale_id', Integer, ForeignKey
('sottoconto_ce.id', onupdate="CASCADE", ondelete="CASCADE"))
)

class SottocontoCE(DeclarativeBase):
    __tablename__ = 'sottoconto_ce'

    id = Column(Integer, primary_key=True)
    nome = Column(Unicode(255), unique=True, nullable=False)
    descrizione = Column(Unicode(255))


class Attivita(DeclarativeBase):
    __tablename__ = 'attivita'

    id = Column(Integer, primary_key=True)
    nome = Column(Unicode(255), unique=True, nullable=False)
    descrizione = Column(Unicode(255))

    sottoconti_ce_proporzionali_ce = relation('SottocontoCE',
         secondary=sottoconti_ce_proporzionali_ce_per_attivita,
 
primaryjoin=id==sottoconti_ce_proporzionali_ce_per_attivita.c.attivita_id,
 
secondaryjoin=sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_id==SottocontoCE.id,
         foreign_keys=
[sottoconti_ce_proporzionali_ce_per_attivita.c.attivita_id,
 
sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_id])

class SottocontiCEProporzionaliCEPerAttivita(DeclarativeBase):
    __table__ = sottoconti_ce_proporzionali_ce_per_attivita
    sottoconto=relation('SottocontoCE',
 
primaryjoin=sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_id==SottocontoCE.id,
                        foreign_keys=
[sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_id])
    attivita=relation('Attivita')
    sottoconto_proporzionale=relation('SottocontoCE',
primaryjoin=sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_proporzionale_id==SottocontoCE.id,
                    foreign_keys=
[sottoconti_ce_proporzionali_ce_per_attivita.c.sottoconto_proporzionale_id])

    def __init__(self, sottoconto=None, attivita=None,
sottoconto_proporzionale=None):
        self.sottoconto=sottoconto
        self.attivita=attivita
        self.sottoconto_proporzionale=sottoconto_proporzionale
//end code

the class SottocontiCEProporzionaliCEPerAttivita is used as a mapping
for the table sottoconti_ce_proporzionali_ce_per_attivita.
the columns sottoconto_proporzionale_id and sottoconto_id are both
foreign keys to class SottocontoCE.
Now suppose sc1 and sc2 are instances of SottocontoCE and att of
Attivita. If I want to create an association such that att owns sc1
which is related to sc2:
assoc = SottocontiCEPRoporzionaliCEPerAttivita(sc1, att, sc2)
everything is fine and when i commit canges a new entry in the table
sottoconti_ce_proporzionali_ce_per_attivita is pushed in the DB
But, if I call
att.sottoconti_ce_proporzionali_ce I get the following from the
interpreter

>>> att.sottoconti_ce_proporzionali_ce
14:27:07,890 INFO  [sqlalchemy.engine.base.Engine.0x...5d90] SELECT
sottoconto_ce.id AS sottoconto_ce_id, sottoconto_ce.nome AS
sottoconto_ce_nome, sottoconto_ce.descrizione AS
sottoconto_ce_descrizione, sottoconto_ce.conto_id AS
sottoconto_ce_conto_id
FROM sottoconto_ce, sottoconti_ce_proporzionali_ce_per_attivita
WHERE ? = sottoconti_ce_proporzionali_ce_per_attivita.attivita_id AND
sottoconti_ce_proporzionali_ce_per_attivita.sottoconto_id =
sottoconto_ce.id
14:27:07,890 INFO  [sqlalchemy.engine.base.Engine.0x...5d90] [1]
[]
>>>

why this is an empty list? I should see sc1...
Thanks again for any help and sorry for the italian names of the
attributes, but they are economical technicalities ^_^

Simone

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