On Sep 10, 2010, at 3:14 AM, Ernst wrote:

> Hi,
> I have manged to set up joined and single table inheritance mappings.
> When relationships get involved I need help.
> 
> I would like to use the state pattern. Class Applicant delegates to a
> subclass of State.
> 
> applicant_table = Table('applicant', metadata,
>  Column('applicant_id',Integer, primary_key=True),
>  Column('_state', Integer, ForeignKey('applicantstate.state_id')),
> )
> 
> 
> appstate_table = Table('applicantstate', metadata,
>  Column('state_id',Integer, primary_key=True),
>  Column('type', String(30),nullable=False),
>  Column('_givenName', String(40))
> )
> 
> # applicant - state relationship, one to one, SQLAlchemy-0.5.8-
> #mapper(Applicant, applicant_table, properties={
> #  'applicantstate':relation(State, uselist=False,
> backref='applicant')
> #})
> 
> mapper(Applicant, applicant_table, properties={
>  'applicantstate':relation(State, backref=backref('applicant',
> uselist=False))
> })
> 
> I tried both relationships and get:
> ProgrammingError: (ProgrammingError) can't adapt '
> INSERT INTO applicant (applicant_id, _state)
> VALUES (%(applicant_id)s, %(_state)s)'
> {'_state': <tg21tut.model.Applicant2.NewStdApp object at 0x9034bec>,
> 'applicant_id': 1L}
> 
> I have omitted the single table inheritance mappings.

The relationship is valid. The error there arises from some inappropriate 
manipulation of objects,  such as setting applicant._state = 
SomeApplicantState(), instead of assigning to the "applicantstate" attribute.   
 Full detail would be needed in order to determine the issue.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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