Gera88 wrote:
>
> Hello.
> I'v get this error while add new record to Service table.
>
>     "many-to-many relation, 'secondaryjoin' is needed as well." %
> (self))
> sqlalchemy.exc.ArgumentError: Could not determine join condition
> between parent/child tables on relation Service.services.  Specify a
> 'primaryjoin' expression.  If this is a many-to-many relation,
> 'secondaryjoin' is needed as well.
>
>
>
> services_table = Table('service', metadata,
>     Column('id', types.Integer, primary_key=True, autoincrement=True),
>     Column('table', types.Unicode(10)), # a or b
>     Column('name', types.Unicode(255), nullable=False),
>     Column('code', types.Integer),
> )
>
> service_btype_table = Table('service_btype', metadata,
>     Column('service_b_id', types.Integer, ForeignKey('service.id'),
> primary_key=True),
>     Column('service_a_id', types.Integer, ForeignKey('service.id'),
> primary_key=True)
> )
>
> mapper(Service, services_table,
>         properties={'services': relation(Service, backref='services',
>                               secondary=service_btype_table)})
>
> Whats wrong in code?

1. the backref is invalid. you're attempting to create a relation called
"services" twice on the same class.
2. the relation is self-referential - it can't be automatically determined
which join to apply for Service->service_type_table and
service_type_table->Service - you need to use both "primaryjoin" and
"secondaryjoin" to define this.  examples are at
http://www.sqlalchemy.org/docs/05/mappers.html#specifying-alternate-join-conditions-to-relation
.




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