i think u should not make 2 separate relations, but one relation on 
one of the tables, with a backref to the other.
i.e. just 
 mapper( T1, t1, properties={"t2s": relation(T2, lazy=False, 
backref='t1')})
do check doco, just in case.

On Friday 27 July 2007 15:07:39 Michal Nowikowski wrote:
> Hello
>
> I've following problem. I've two tables (t1, t2) and relation t1
> (one) - t2 (many):
>   mapper(T1, t1, properties={"t2s": relation(T2, lazy=False)})
>   mapper(T2, t2, properties={"t1": relation(T1, lazy=False)})
>
> When I add row to t1, then to t2, and then run query for first row
> in t1, I see one
> element in collection t2s - it is ok.
> Then when I add second row to t2, the collection in t1 object is
> not updated.
> It still contains only one element.
>
> Example below.
>
> Could you tell me how to refresh collection in one-to-many
> relation???
>
> Regards
> Michal Nowikowski
>
>
> from sqlalchemy import *
>
> md = MetaData('sqlite:///a.db', echo=False)
> t1 = Table("t1", md,
>            Column("id", Integer, primary_key=True),
>            Column("version", Integer))
>
> t2 = Table("t2", md,
>            Column("id", Integer, primary_key=True),
>            Column("name", String),
>            Column("t1_id", Integer, ForeignKey("t1.id")))
>
> md.create_all()
> s = create_session()
>
> class T1(object):
>     pass
> class T2(object):
>     pass
>
> mapper(T1, t1, properties={"t2s": relation(T2, lazy=False)})
> mapper(T2, t2, properties={"t1": relation(T1, lazy=False)})
>
> a1 = T1()
> s.save(a1)
> s.flush()
>
> a2 = T2()
> a2.t1_id = a1.id
> a2.name = "AAA"
> s.save(a2)
> s.flush()
>
> ra1 = s.query(T1).first()
> print [ a.name for a in ra1.t2s ]
>
> a22 = T2()
> a22.t1_id = a1.id
> a22.name = "BBB"
> s.save(a22)
> s.flush()
>
> rra1 = s.query(T1).first()
> print [ a.name for a in rra1.t2s ]
>
>
> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to