I have now moved on a bit and came up against a brick wall :/
I have a ClassifiedPage instance which inherits from MagazinePage which
in-turn inherits from Page.
Log:
[2006-05-30 21:43:25,602] [engine]: INSERT INTO page (page_no, type)
VALUES (?, ?)
[2006-05-30 21:43:25,602] [engine]: [1, 'c']
[2006-05-30 21:43:25,603] [engine]: INSERT INTO magazine_page (page_id,
magazine_id, orders) VALUES (?, ?, ?)
[2006-05-30 21:43:25,603] [engine]: ['0', 1, '']
[2006-05-30 21:43:25,605] [engine]: INSERT INTO classified_page
(magazine_page_id, titles) VALUES (?, ?)
[2006-05-30 21:43:25,605] [engine]: [0, '']
[2006-05-30 21:43:25,607] [engine]: COMMIT
As you can see, the inheritance tree works, except that the
magazine.page_id and classified.page_id are not being correctly updated.
I have included a patch to the test.py I attached in my previous mail.
Do I need to create a separate polymorphic_union for ClassifiedPage? and
if so, what would that look like?
TIA ...
Nick
Michael Bayer wrote:
> Hey Nick -
>
> I ran this test (which is well-written, youve understood the docs very
> well) with my favorite constraint checker, Postgres, and it does in fact
> fail on 0.2.1. Fortunately, it does not fail when testing with the
> fixes I have just made today, i think its the same issue someone else
> raised today (a lot has changed with the persistence mechanism with
> regards to inheritance structures recently). Try checking out the
> trunk, rev 1554. also, one slight change to your program:
[[ snip ]]
--- test.py 2006-05-30 21:38:53.000000000 +0100
+++ test.py 2006-05-30 21:41:56.000000000 +0100
@@ -50,7 +50,7 @@
Column('name', String(45), default=''),
)
-# mapping objects
+# set-up mappers
class BaseObject(object):
def __init__(self, *args, **kwargs):
@@ -103,14 +103,11 @@
pass
class MagazinePage(Page):
- def __init__(self, *args, **kwargs):
- Page.__init__(self, *args, **kwargs)
+ pass
class ClassifiedPage(MagazinePage):
pass
-# define mapping
-
publication_mapper = mapper(Publication, publication_table)
issue_mapper = mapper(Issue, issue_table, properties = {
@@ -131,6 +128,7 @@
page_join = polymorphic_union(
{
'm': page_table.join(magazine_page_table),
+ 'c': page_table.join(magazine_page_table).join(classified_page_table),
'p': page_table.select(page_table.c.type=='p'),
}, None, 'page_join')
@@ -142,12 +140,10 @@
page_mapper = mapper(Page, page_table, select_table=page_join,
polymorphic_on=page_join.c.type, polymorphic_identity='p')
magazine_page_mapper = mapper(MagazinePage, magazine_page_table,
inherits=page_mapper, polymorphic_identity='m', properties={
- 'magazine': relation(Magazine)
+ 'magazine': relation(Magazine, backref=backref('pages', cascade='all,
delete-orphan'))
})
-magazine_mapper.add_property('pages', relation(MagazinePage, lazy=True,
private=True))
-
-#classified_page_mapper = mapper(ClassifiedPage, classified_page_table,
inherits=MagazinePage.mapper, polymorphic_identity='c')
+classified_page_mapper = mapper(ClassifiedPage, classified_page_table,
inherits=magazine_page_mapper, polymorphic_identity='c')
session = objectstore.get_session()
@@ -166,9 +162,10 @@
magazine = Magazine(location=location,size=page_size)
-page = MagazinePage(magazine=magazine,page_no=1)
+page = ClassifiedPage(magazine=magazine,page_no=1)
session.flush()
+session.clear()
'''
p = session.query(Publication).selectone_by(name='Test')