On Feb 17, 2012, at 4:44 AM, Jakob D. wrote:

> From what I've read these errors are usually solved by adding use_alter=True 
> and inverse.
> 
> It doesn't work for me though.
> 
> I have ridiculously many relations between two tables. But that's how it is 
> and I cannot refactor the model at this point. 
> 

anyway, it's a little unclear what the difference between Project.user_account 
and Project.workers is....I created a sample declarative model that illustrates 
workers/client/creator in both directions, placing the post_updates on the 
many-to-ones to minimize the extra UPDATE statements and just putting use_alter 
on User.project_id, so you can see it working here.   You'd have to figure out 
exactly how to make Elixir do the same thing:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base= declarative_base()


class Project(Base):
    __tablename__ = 'project'
    id      = Column(String(100), primary_key=True)
    client_id = Column(String(80), ForeignKey('user.username'))
    creator_id = Column(String(80), ForeignKey('user.username'))
    workers = relationship("User", backref="assigned_project", 
                                primaryjoin="Project.id==User.project_id")
    client  = relationship("User", backref="owned_projects", 
                                primaryjoin="Project.client_id==User.username",
                                post_update=True)
    creator = relationship("User", backref="created_projects", 
                                primaryjoin="Project.creator_id==User.username",
                                post_update=True)

class User(Base):
    __tablename__ = 'user'
    username            = Column(String(80),  primary_key=True)
    project_id = Column(String(100), ForeignKey("project.id", use_alter=True,
                                        name="fk_user_project_id"))

e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
s = Session(e)

p1 = Project(id="someproject")
u1 = User(username="someuser")
p1.client = p1.creator = u1
u1.assigned_project = p1
s.add(u1)
s.commit()


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