Michael Bayer wrote:
> I should learn to explain better what "syncrules" are about, so heres
> an attempt:
> 
> when you have a table A and a table B, and then a mapping relationship
> between A and B, theres a join condition set up between the two tables.
>  By default, it draws from the foreign keys of the tables.
> Alternatively, you can send "primaryjoin" and optionally
> "secondaryjoin" (if you have a secondary association table in the
> middle) to specify this join condition manually.
> 
> Lets take a join condition of A.a_id=B.a_id.   That means when I create
> an instance mapped to table "A", it will have a primary key attribute
> "a_id".  An instance mapped to table "B" will have an attribute "a_id"
> as well which contains the id of its related "A" object.
> 
> The syncrule generated for this relationship is then "after saving an
> instance of "A", copy the value of its "a_id" attribute to the "a_id"
> attribute on all the "B" elements attached to it".  The syncrule is
> generated in the sqlalchemy.orm.sync module, and traverses across the
> join conditions (i.e. the "primaryjoin") in order to generate the rule.
> 
> If the syncrules execute and dont manage to find any rules that map
> attributes from "A" to "B", its clear that the mapper has no way of
> relating in the database the "A"/"B" relationship.  So for now, it
> assumes that its an error.  Since if you have made a relation() from A
> to B, the mapper needs to be able to persist it.
> 
> So when you get that error message, it means the join conditions are
> not taking into account the two tables involved in such a way that the
> syncrules can figure it out, usually because the two tables are related
> via an intermediary table which is stuck in the middle of the join (it
> doesnt handle that).

I have a setup similar to this and would prefer not to use an 
association table.

A, B and C are tables.

A  <-FK  B(intermediate)  ->  C

C could possibly be truncated and restored so I don't want an FK 
deleting or restricting records in B.

Table B does not have a Foreign Key defined for C because I don't want 
changes in C to affect B. Is there a way to define the foreign key such 
that it doesn't add a FK constraint to the database, but understands the 
relationship?

I'm creating A and B via metadata.create_all() and I don't want a FK for 
B->C created, but do want sqlalchemy to know about the relationship so 
that I could define it like:

        mapper(AClass, A, properties={'C' : relation(C, secondary=B)})

So the only difference is that there would be no Database FK, but I 
don't want to resort to manually deleting it if I dont' have to. Is 
there a nice way to do this?

Randall


> 
> The syncrules are only needed for saving objects, not loading them,
> which is why I added the "viewonly" flag to relations in case you
> really want a relation() that uses an unusual join, and you dont care
> about the mapper being able to persist it.
> 
> 
> > 
> 


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