On Fri, Dec 04, 2009 at 01:27:46PM -0500, Michael Bayer wrote:
> 
> On Dec 4, 2009, at 1:18 PM, Alessandro Dentella wrote:
> 
> >>> Is the only solution to attach an instance (u.job = myjob) or is there
> >>> another solution that doesn't require me to build the instance?
> >> 
> >> if you want SQLA's delete-orphan capability, that's the only way.  If you 
> >> want to rely upon CASCADE rules in your DB to handle it instead, that's 
> >> another way to go.
> > 
> > thanks, and really... managing in the db is such a simple thing...
> > 
> > Is there a why to find out the related class (that one u.job should be
> > instance of) so that I can issue a query on that?
> 
> 
> err, given what to start with ?

ops. Let's say starting from the class and the instance.

class Project(Base):
     __tablename__ = "project"
     id = Column(Integer, primary_key=True)
     name               = Column(String(30), nullable=False)

class Delivery(Base):
     __tablename__ = 'delivery'
     id            = Column(Integer, primary_key=True)
     project_id        = Column(ForeignKey(Project.id), nullable=False)
     
     project = orm.relation('Project', backref=orm.backref('deliveries', 
cascade="all, delete-orphan", lazy=False))


sess = session()
p = Project()
d = Delivery()
d.project_id = p.id

# now I want to create automatically the instance 'p' having just 

  * the value 'p.id'
  * d
  * the name of the attribute (that is a ForeignKey) project_id

Since I need to issue:

p = sess.query(Project).get(p.id)

is there a way to get Project (the class) from d and 'project_id'

I hope now it's a little bit clearer

sandro
*:-)




-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.org        SQLkit home page - PyGTK/python/sqlalchemy

--

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