hey arnar -
I cant reproduce this one with what youve given me. If i just set up
"jobs" and "pages" mappers (no page version stuff since its not in
the example), and dont compile anything, the creation of the Job()
object compiles the "jobs" mapper which properly hits the "pages"
backref.
from sqlalchemy import *
from datetime import datetime
__meta__ = MetaData()
jobs = Table("jobs", __meta__,
Column("jobno", Unicode(15), primary_key=True),
Column("created", DateTime, nullable=False,
default=datetime.now),
Column("deleted", Boolean, nullable=False,
default=False))
class Job(object):
pass
mapper(Job, jobs)
pages = Table("pages", __meta__,
Column("jobno", Unicode(15), ForeignKey
("jobs.jobno"),primary_key=True),
Column("pagename", Unicode(30), primary_key=True),
Column("created", DateTime,
nullable=False,default=datetime.now),
Column("deleted", Boolean, nullable=False,
default=False),
Column("current_version", Integer))
class Page(object):
pass
mapper(Page, pages, properties={
'job': relation(Job, backref=backref('pages',
cascade="all,delete-orphan")),
})
j = Job()
print j.pages
On Jun 19, 2006, at 8:45 AM, Arnar Birgisson wrote:
> Hi there,
>
> I have two tables mapped like this:
>
> jobs = Table("jobs", __meta__,
> Column("jobno", Unicode(15), primary_key=True),
> Column("created", DateTime, nullable=False,
> default=datetime.now),
> Column("deleted", Boolean, nullable=False,
> default=False))
>
> class Job(object):
>
> @constructor
> def __init__(self, jobno=None):
> if jobno:
> self.jobno = jobno
>
> mapper(Job, jobs)
>
>
> pages = Table("pages", __meta__,
> Column("jobno", Unicode(15), ForeignKey("jobs.jobno"),
> primary_key=True),
> Column("pagename", Unicode(30), primary_key=True),
> Column("created", DateTime, nullable=False,
> default=datetime.now),
> Column("deleted", Boolean, nullable=False,
> default=False),
> Column("current_version", Integer))
>
> class Page(object):
>
> @constructor
> def __init__(self, job=None, pagename=None):
> if job:
> self.job = job
> if pagename:
> self.pagename = pagename
> self.currentversion = PageVersion(self, 1)
>
> def addVersion(self):
> self.currentversion = PageVersion(self,
> self.currentversion.version+1)
> return self.currentversion
>
> mapper(Page, pages, properties={
> 'job': relation(Job, backref=backref('pages', cascade="all,
> delete-orphan")),
> 'currentversion': relation(PageVersion,
> foreignkey=pages.c.current_version,
> primaryjoin=and_
> (pages.c.jobno==pageversions.c.jobno,
>
> pages.c.pagename==pageversions.c.pagename,
>
> pages.c.current_version==pageversions.c.version),
> post_update=True),
> 'versions': relation(PageVersion, cascade="all, delete-orphan",
> order_by=pageversions.c.version,
> backref='page', lazy=False)
> })
>
>
> The problem is that if I create Job instances before ever referencing
> Page, they have no "pages" property, since it's declared in the Page
> mapper.
>
> The solution would obviously be to compile my mappers manually - but
> is there a way to turn of this deferred mapper compilation behaviour?
>
> Arnar
>
>
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users