hi I finally made this work. Thanks for the doc link although it
wasn't clear enough. As it's using the "classical" syntax. But the
last paragraph of that section gave me a good hint.

I have extracted the relevant parts of my model and I got to something
that could become a FAQ item or a tutorial or an addition to the docs?
The question is which and where? Here is the code. The one thing that
still puzzles me is that I had to move my State table declaration
before Policy as using "State.code" or something similar didn't work.

class State(DeclarativeBase):
    __tablename__ = 'state'

    code = Column(String(2), primary_key=True)
    name = Column(String(50))

class Policy(DeclarativeBase):
    __tablename__ = 'policy'

    id = Column(Integer, primary_key=True)
    state_of_policy_code = Column(String(2) ,ForeignKey('state.code'))
    state_of_domicile_code = Column(String(2) ,ForeignKey('state.code'))
    policy_state =
relation('State',backref='state_policies',primaryjoin=state_of_policy_code==State.code)
    domicile_state =
relation('State',backref='domicile_policies',primaryjoin=state_of_domicile_code==State.code)

#test code to ran, maybe in a python shell for proper feedback.
ny = model.State()
ny.code = 'ny'
fl = model.State()
fl.code = 'fl'
p = model.Policy()
p.policy_state = ny
p.domicile_state = fl
model.save(p)
model.DBSession.flush()#note this is TurboGears place for SQLAlchemy's
session object.
ny.state_policies[0].policy_state.code



On Fri, Sep 26, 2008 at 9:13 AM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> Information on "primaryjoin" and "secondaryjoin" is available at:
>
> http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_customjoin
>
>
> On Sep 25, 2008, at 8:18 PM, Jorge Vargas wrote:
>
>>
>> hello I'm having a bit of troubles with the following case.
>>
>> http://paste.turbogears.org/paste/8177
>>
>> This is the error I'm getting. Now I know it has to do with SA not
>> being able to know to which field to map state.id, but how do I fix
>> it?
>>
>> "Specify a 'primaryjoin' expression.  If this is a many-to-many
>> relation, 'secondaryjoin' is needed as well." % (self))
>> sqlalchemy.exc.ArgumentError: Could not determine join condition
>> between parent/child tables on relation MappedPolicy.state.  Specify a
>> 'primaryjoin' expression.  If this is a many-to-many relation,
>> 'secondaryjoin' is needed as well.
>>
>> PS: in case you where wondering for commodity I need those to values
>> present in the table and since they are always going to be two it
>> isn't such a bad design decision... although I may optimize the
>> "state" table into a python list or dict in the future. I want to know
>> how to fix this.
>>
>> >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to