On Apr 19, 2011, at 12:57 PM, Kent Bower wrote:

> So, what would you suggest the "right answer" is in this case?  In the real 
> world scenario we have a potentially good reason to avoid the association 
> proxy approach since that involves an additional table which may be unneeded.
> 
> Is the best answer just to provide the foreign keys as I did?

it is !  or just have the warning, its not a big deal.   id make sure 
viewonly=True is set as well.


> 
> 
> On 4/19/2011 11:47 AM, Michael Bayer wrote:
>> On Apr 19, 2011, at 9:04 AM, Kent wrote:
>> 
>>> I'm getting an SAWarning (0.6.4 and also 0.7b5dev) which has a message
>>> that confuses me, so I've duplicated the problem with a script:
>>> ===================================================
>>> 
>>> mapper(PostSpotLight, spotlights_table,
>>>    properties = {'postkeywords':
>>>        relationship(Keyword, secondary=post_keywords,
>>> 
>>> primaryjoin=spotlights_table.c.post_id==post_keywords.c.post_id)}
>>> )
>>> 
>>> [...]/sqlalchemy-default/lib/sqlalchemy/orm/properties.py:900:
>>> SAWarning: No ForeignKey objects were present in secondary table
>>> 'post_keywords'.  Assumed referenced foreign key columns
>>> 'post_keywords.keyword_id', 'post_keywords.post_id' for join condition
>>> 'spotlights.post_id = post_keywords.post_id' on relationship
>>> PostSpotLight.postkeywords
>>>  eq_pairs = self._sync_pairs_from_join(self.primaryjoin, True)
>>> 
>>> Why is the complaint that there are No ForeignKey objects were present
>>> in secondary table 'post_keywords', when clearly there are?
>> Well this is the message knowing something was wrong but not expressing it 
>> in a way that I expected when I wrote it.  post_keywords has no foreign keys 
>> that refer to the "spotlights" table.    if a primaryjoin condition is 
>> given, it only cares about foreign keys that express components of the join 
>> condition.   this used to be an error condition but eventually I figured 
>> that things would just "work" if I assumed the cols in post_keywords were 
>> FKs, after I saw someone confused by placing a "secondary" table that in 
>> fact had no FKs on it.
>> 
>>> ***Furthermore, if I pass the relationship this:
>>> 
>>> foreign_keys=[post_keywords.c.post_id,post_keywords.c.keyword_id]
>>> 
>>> then the warning goes away, but all I've done is specify the very
>>> foreign_keys that already exist.***
>> well in this case you give it some columns, but not what they reference to.  
>> So it sees "post_id" and it says, oh, thats the FK that points to 
>> spotlights.post_id.
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" 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/sqlalchemy?hl=en.
> 

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

Reply via email to