Hello, i am trying to figure out how association_proxy() could be used
in case of  "regular" rather than declarative style definitions. I
can't figure out what can be done to mitigate the issue and hence i
seek help here.

Thanks in advance...

The code below is copy/pasted sample from the official docs without
declarative part and when run outputs this:

Traceback (most recent call last):
  File "d.py", line 36, in <module>
    'keywords': association_proxy('kw', 'keyword')
  File "/usr/local/python/3.2/lib/python3.2/site-packages/
SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/orm/__init__.py", line 1114, in
mapper
    return Mapper(class_, local_table, *args, **params)
  File "/usr/local/python/3.2/lib/python3.2/site-packages/
SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/orm/mapper.py", line 201, in
__init__
    self._configure_properties()
  File "/usr/local/python/3.2/lib/python3.2/site-packages/
SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/orm/mapper.py", line 818, in
_configure_properties
    self._configure_property(key, prop, False)
  File "/usr/local/python/3.2/lib/python3.2/site-packages/
SQLAlchemy-0.7.4-py3.2.egg/sqlalchemy/orm/mapper.py", line 1016, in
_configure_property
    % (key, prop))
sqlalchemy.exc.ArgumentError:
keywords=<sqlalchemy.ext.associationproxy.AssociationProxy object at
0x34ad190> is not an instance of MapperProperty or Column



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sqlalchemy import Column, Integer, String, ForeignKey, Table
from sqlalchemy.orm import relationship, mapper
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.schema import MetaData

metadata = MetaData()

class User():
    def __init__(self, name):
        self.name = name

class Keyword():
    def __init__(self, keyword):
        self.keyword = keyword

user_table = Table('user', metadata,
    Column('id', Integer, primary_key=True),
    Column('name', String(64))
)

keyword_table = Table('keyword', metadata,
    Column('id', Integer, primary_key=True),
    Column('keyword', String(64))
)

userkeywords_table = Table('userkeywords', metadata,
    Column('user_id', Integer, ForeignKey("user.id")),
    Column('keyword_id', Integer, ForeignKey("keyword.id"))
)

mapper(Keyword, keyword_table)

mapper(User, user_table,
    properties={
        'kw': relationship(Keyword, secondary=userkeywords_table),
        'keywords': association_proxy('kw', 'keyword')
    })

user = User('jek')
user.keywords.append('cheese inspector')
print (user.keywords)
user.keywords.append('snack ninja')
print (user.kw)

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