-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10 Feb 2011, at 14:35, cvr wrote:
Hi

I'm trying to join a table that is related through a ManyToMany
relationship. However, I cannot seem to get this to work, I always get
an error " Can't find any foreign key relationships between ..."
Yet the CREATE syntax shows, that there are FKs that get defined, so I
wonder: Do I have to manually add other FKs?

Please see here for an interactive python session to replicate the
problem:
http://bpaste.net/show/13530/

Thanks.
Chris




> I'm trying to join a table that is related through a ManyToMany
> relationship. However, I cannot seem to get this to work, ...

> Do I have to manually add other FKs?

Not in my experience but I tend to (gratefully) work directly with the elixir-delivered objects:

>>> from elixir import *
>>> from sqlalchemy import create_engine
>>> metadata.bind = create_engine('sqlite:///:memory:')
>>> metadata.bind.echo=False
>>> class A(Entity):
...     bs = ManyToMany('B')
...
>>> class B(Entity):
...     aas = ManyToMany('A')
...
>>> setup_all()
>>> create_all()
>>> baz = B()
>>> foo = A()
>>> foo.bs.append(baz)
>>> foo.bs
[<__main__.B object at 0x1343e30>]
>>> baz.aas
[<__main__.A object at 0x135a110>]
>>> [(i, i.bs) for i in session.query(A).all()]
[(<__main__.A object at 0x135a110>, [<__main__.B object at 0x1343e30>])]
>>> [(i, i.aas) for i in session.query(B).all()]
[(<__main__.B object at 0x1343e30>, [<__main__.A object at 0x135a110>])]

Dunno if this helps.


- --
Cheers,

Graham

http://bel-epa.com/gjh/








-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAk1UBuwACgkQOsmLt1NhivxjugCg+q/l6dOpYr0qnnMPDhQPjgu0
DDYAn0aK7O2LZ/coGVRrd6zZypiQmdRLiQCVAgUBTVQG7FnrWVZ7aXD1AQJzDwQA
paw6Qtr1dtO4KypwW/K/1AYqJ1WlkyWd5umbWmHwdVZOk7ySbpJhYZelaTmZLYmn
kiNAF6IMw4aGAGjbRnAJyZpRvFEdw545Rr0+TKVOexE9JaKnkyJgDhfFyJJieh0Q
vX7Q5wNgyM4ic4JdD0bGpUSxCzpvVz58lqA7XxBquQ4=
=njl3
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en.

Reply via email to