> B.get_by(a=a1)
get_by() only supports column-based properties and scalar values, it
doesnt support using relations and objects as keys/values.
this would be best expressed as:
B.get_by(a_id=a1.id)
On Sep 11, 2006, at 4:04 PM, Charles Duffy wrote:
> ######## BEGIN CODE SNIPPET
> import sqlalchemy
> from sqlalchemy import String, ForeignKey
> from sqlalchemy.ext.activemapper import ActiveMapper, column,
> one_to_many
> import sqlalchemy.ext.activemapper as activemapper
>
> class A(ActiveMapper):
> class mapping:
> id = column(String, primary_key=True)
> Bs = one_to_many('B', colname='a_id', backref='a')
>
> class B(ActiveMapper):
> class mapping:
> a_id = column(String, foreign_key=ForeignKey('a.id'),
> primary_key=True)
> c = column(String, nullable=False, primary_key=True)
>
> activemapper.metadata.connect('sqlite:///:memory:')
> activemapper.metadata.create_all()
>
> a1 = A(id='foo')
>
> b1 = B(a=a1, c='qux')
> b2 = B(a=a1, c='quux')
>
> B.get_by(a=a1)
> ######## END CODE SNIPPET
>
> $ python2.4 sa-test.py
> Traceback (most recent call last):
> File "sa-test.py", line 25, in ?
> B.get_by(a=a1)
> File ".../lib/sqlalchemy/ext/assignmapper.py", line 7, in do
> return getattr(query, name)(*args, **kwargs)
> File ".../lib/sqlalchemy/orm/query.py", line 71, in get_by
> x = self.select_whereclause(self.join_by(*args, **params),
> limit=1)
> File ".../lib/sqlalchemy/orm/query.py", line 108, in join_by
> c = (prop.columns[0]==value) & self.join_via(keys)
> AttributeError: 'LazyLoader' object has no attribute 'columns'
>
> ...this running against SQLAlchemy trunk r1865.
>
>
> ----------------------------------------------------------------------
> ---
> Using Tomcat but need to do more? Need to support web services,
> security?
> Get stuff done quickly with pre-integrated technology to make your
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users