Michael Bayer wrote:
> which two tables are concrete ?  I dont see the "concrete=True" keyword
> used in your mapping setup, but then again I don't see the "inherits"
> keyword either

Sorry, I think I accidentally edited that out before posting. Though I
did indeed have a polymorphic_identity without having concrete specified
to True, so thanks for pointing out that this doesn't actually do
anything (I had foolishly assumed it was required to make sure the type
in the node table was filled correctly).

The problem is that if on the uc_products table vid is set is a primary
key (and not nid as it is for the parent node table) a creation of a
Product results in the following rows:

node:
+-----+-----+---------+
| nid | vid | type    |
+-----+-----+---------+
| 1   | 1   | product |
+-----+-----+---------+

node_revisions:
+-----+-----+
| nid | vid |
+-----+-----+
| 1   | 1   |
+-----+-----+

uc_products:
+-----+-----+
| vid | nid |
+-----+-----+
| 0   | 1   |
+-----+-----+

Note how vid for uc_products remains on the default value (0). The
mapping below would work if nid was the primary key for the uc_products
table instead of vid:

uc_products_table = Table("uc_products", metadata,
    Column("vid", Integer, ForeignKey("node_revisions.vid"),
primary_key=True), # vid instead of nid is the primary key
    Column("nid", Integer, ForeignKey("node.nid")),
    autoload=True
)

uc_products_mapper = mapper(Product, uc_products_table,
    inherits=node_mapper,
    properties={
        "revision": relation(NodeRevision, post_update=True)
    }
)

Then a product would be created as:

product = Product()
product.latest_revision = NodeRevision()
product.revision = product.latest_revision

Which probably isn't ideal, but would at least work.

I'm trying to figure out if there is a way to have vid remain the
primary key for uc_products.

Best regards,

Bruce


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to