On Sep 7, 2011, at 11:53 AM, werner wrote:

> Michael,
> 
> On 09/07/2011 05:10 PM, Michael Bayer wrote:
>> On Sep 7, 2011, at 4:40 AM, werner wrote:
>> 
>>> or:
>>> Region_LV.language = sao.relationship('Language',
>>>                   primaryjoin="Country_LV.fk_language_id==Language.id",
>>>                   foreign_keys=[Country_LV.__table__.c.fk_language_id])
>>> 
>>> I get:
>>> sqlalchemy.exc.ArgumentError: Column-based expression object expected for 
>>> argument 'foreign_keys'; got: 'Country_LV.fk_language_id', type<type 'str'>
>> this one above is the one that doesn't make any sense (also its probably how 
>> the relationship should be set up).
> Sorry that was a copy/paste error on my part.
>>    Clearly x.__table__.c.somename is a Column object, not a string.   
>> Something is up with what you're sending it.     I've tried to reproduce 
>> with no luck.  See attached.   Also I don't even need the 
>> primaryjoin/foreignkeys if the originating Table upon which the view is 
>> based has foreign keys to the parent.
>> 
> The additional column is in my case added in to the view as the base table 
> doesn't have it and it is filled by the stored procedure (which combines the 
> base table plus the localized table ...) , i.e.:
> 
> def view(name, metadata, selectable):
>    t = table(name)
> 
>    for c in selectable.c:
>        c._make_proxy(t)
> 
>    lc = sasql.column("stuff_id", sa.Integer)
>    t.append_column(lc)
> 
> But what I had overlooked/forgotten to include was the "__mapper_args__ = 
> {"primary_key":__table__.c.id}" line.
> 
> After adding this the relationship as shown at the beginning it works.

well that's also strange.   If the mapper is not able to find a primary key, 
the error is very clear:

sqlalchemy.exc.ArgumentError: Mapper Mapper|MSView|msview could not assemble 
any primary key columns for mapped table 'msview'

not sure why that isn't what you were seeing.

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