[sqlalchemy] Re: scalar association_proxy

2011-01-20 Thread AgentOrange

 Maybe you can squelch the exception by using a synonym with the descriptor 
 argument to map to a fake property.

Oooh, I had not come across this construct before - looks as if it
might do exactly what I want. I might even be able to make a decorator
that wraps this all up nicely. Thank you very much; I shall let you
know how I get on!

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



[sqlalchemy] Re: scalar association_proxy

2011-01-19 Thread AgentOrange
Hi ho,

Thanks for the swift reply!

 Did you use uselist=False on foo.bar and the associationproxy? It would nice 
 if you could show some 
 code.http://www.sqlalchemy.org/docs/orm/extensions/associationproxy.html?h...

Yes I did. The code is more complicated as it has a bunch of other
stuff in it, but here's a condensation:

class Foo(Base):
id = Column(Integer, primary_key = True)
foo_bar_join = relationship(FooBar, primaryjoin = (id ==
FooBar.id_foo), uselist = False)
bar = association_proxy('foo_bar_join', 'bar', creator = lambda x:
FooBar(bar = x) )

class Bar(Base):
id = Column(Integer, primary_key = True)

class FooBar(Base):
id_foo = Column(Integer, ForeignKey('foo.id'), primary_key = True)
id_bar = Column(Integer, ForeignKey('bar.id'), primary_key = True)

bar = relationship(Bar, primaryjoin = (id_bar == Bar.id))
other_stuff = Column(Integer)

The problem comes if you try to fetch 'bar' from an instance of 'Foo'
for which there is no entry in the foo_bar join table.

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



Re: [sqlalchemy] Re: scalar association_proxy

2011-01-19 Thread A.M.

On Jan 19, 2011, at 1:29 PM, AgentOrange wrote:

 Hi ho,
 
 Thanks for the swift reply!
 
 Did you use uselist=False on foo.bar and the associationproxy? It would nice 
 if you could show some 
 code.http://www.sqlalchemy.org/docs/orm/extensions/associationproxy.html?h...
 
 Yes I did. The code is more complicated as it has a bunch of other
 stuff in it, but here's a condensation:
 
 class Foo(Base):
id = Column(Integer, primary_key = True)
foo_bar_join = relationship(FooBar, primaryjoin = (id ==
 FooBar.id_foo), uselist = False)
bar = association_proxy('foo_bar_join', 'bar', creator = lambda x:
 FooBar(bar = x) )
 
 class Bar(Base):
id = Column(Integer, primary_key = True)
 
 class FooBar(Base):
id_foo = Column(Integer, ForeignKey('foo.id'), primary_key = True)
id_bar = Column(Integer, ForeignKey('bar.id'), primary_key = True)
 
bar = relationship(Bar, primaryjoin = (id_bar == Bar.id))
other_stuff = Column(Integer)
 
 The problem comes if you try to fetch 'bar' from an instance of 'Foo'
 for which there is no entry in the foo_bar join table.

Maybe you can squelch the exception by using a synonym with the descriptor 
argument to map to a fake property.

Cheers,
M

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