Hi, <mailto:sqlalchemy@googlegroups.com>
I have the use case to map a many to many relation on a existing many to
many relation.
(Means I want to assign a connection table with 2 primary keys to a
connection table with 3 primary keys)
I tried a lot of things but nothing seems to work.
Basically, I have a Purchase Requisition Object on that can be assigned
various (Cost Center ID / Budget ID) Pairs.(means a connection table)
I map the connection tables to associationObjects and tried to use the
AssociationProxy Extension and map a List "assignedBCCs" to the Purchase
Requisition Object, so I can (theoretically) directly assign BCC Objects
without using the Association....(what I thought)
Read access works, and manipulations on the assignedBCCs list seem to
work on the objects, but the changes are not written into the DB.
Anyone has experiences with this kind of relationship?
Here the corresponding code.
I am sorry, it is not a complete working testcase, and the tables are
only MySql without the foreign keys. (only the output of the dbdesigner...)
Nevertheless, until this point I implemented working 1:n and n:1
relationships on the tables and this shouldn't be the reason why it is
not working.
Thank you for any help. Dennis
----------------------------------------------------------------------------------------------------------------------
tables
----------------------------------------------------------------------------------------------------------------------
CREATE TABLE `pr_PurchaseRequisition` (
`pr_PurchaseRequisition_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`pr_PurchaseRequisition_ID`)
)
TYPE=InnoDB;
CREATE TABLE
`pr_PurchaseRequisition_has_CELLS_budget_has_CELLS_costCenter` (
`pr_PurchaseRequisition_ID` INTEGER UNSIGNED NOT NULL,
`CELLS_costCenter_ID` INTEGER UNSIGNED NOT NULL,
`CELLS_budget_ID` INTEGER UNSIGNED NOT NULL,
`percentage` FLOAT NULL,
PRIMARY KEY(`pr_PurchaseRequisition_ID`, `CELLS_costCenter_ID`,
`CELLS_budget_ID`)
)
TYPE=InnoDB;
CREATE TABLE `CELLS_budget_has_CELLS_costCenter` (
`CELLS_budget_ID` INTEGER UNSIGNED NOT NULL,
`CELLS_costCenter_ID` INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(`CELLS_budget_ID`, `CELLS_costCenter_ID`)
)
TYPE=InnoDB;
CREATE TABLE `CELLS_budget` (
`CELLS_budget_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`budgetCode` VARCHAR(10) NULL,
`name` VARCHAR(100) NULL,
PRIMARY KEY(`CELLS_budget_ID`)
)
TYPE=InnoDB;
CREATE TABLE `CELLS_costCenter` (
`CELLS_costCenter_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`CELLS_division_ID` INTEGER UNSIGNED NOT NULL,
`name` VARCHAR(45) NULL,
`budgetCode` VARCHAR(10) NULL,
PRIMARY KEY(`CELLS_costCenter_ID`)
)
TYPE=InnoDB;
CREATE TABLE `CELLS_division` (
`CELLS_division_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
PRIMARY KEY(`CELLS_division_ID`)
)
TYPE=InnoDB;
----------------------------------------------------------------------------------------------------------------------
models
----------------------------------------------------------------------------------------------------------------------
class PRBudgetCostCenterAssociation(object):
pass
class BudgetCostCenterAssociation(object):
pass
def create_BCC(BCC):
new = PRBudgetCostCenterAssociation()
new.budgetCostCenter = BCC
return new
class PurchaseRequisition( DomainRecord ):
implements(IPurchaseRequisition)
assignedBCCs =
AssociationProxy('purchaseRequisitionBudgetCostCenter',
'budgetCostCenter', creator=create_BCC)
def create_budget_association(budget):
ka = KeywordAssociation()
ka.keyword = keyword
return ka
class CELLSCostCenter( DomainRecord ):
implements( ICELLSCostCenterTable )
assignedBudgets = AssociationProxy('associatedBudgets', 'budget',
creator=create_budget_association)
class PRHasBudgetHasCostCenter( DomainRecord ):
implements( IPRHasBudgetHasCostCenterTable )
class CELLSBudget( DomainRecord ):
implements( ICELLSBudgetTable )
class CELLSBudgetHasCostCenter( DomainRecord ):
implements( ICELLSBudgetHasCostCenterTable )
----------------------------------------------------------------------------------------------------------------------
mappers
----------------------------------------------------------------------------------------------------------------------
budget_mapper = bind_mapper( app_model.CELLSBudget,
app_schema.CELLSBudgetTable)
cost_center_mapper = bind_mapper( app_model.CELLSCostCenter,
app_schema.CELLSCostCenterTable,
properties={
'associatedBudgets' :
relation(app_model.BudgetCostCenterAssociation, lazy=False,
cascade="save-update"),
'division':
relation(app_model.CELLSDivision,
lazy=True),
})
mapper(app_model.BudgetCostCenterAssociation,
app_schema.CELLSBudgetHasCostCenterTable,
primary_key=[app_schema.CELLSBudgetHasCostCenterTable.c.CELLS_costCenter_ID,
app_schema.CELLSBudgetHasCostCenterTable.c.CELLS_budget_ID],
properties={
'budget' : relation(app_model.CELLSBudget, lazy=False) ,
}
)
mapper(app_model.PRBudgetCostCenterAssociation,
app_schema.PRHasBudgetHasCostCenterTable,
primary_key=[app_schema.PRHasBudgetHasCostCenterTable.c.pr_PurchaseRequisition_ID,
app_schema.PRHasBudgetHasCostCenterTable.c.CELLS_costCenter_ID,
app_schema.PRHasBudgetHasCostCenterTable.c.CELLS_budget_ID],
properties={
'budgetCostCenter' :
relation(app_model.BudgetCostCenterAssociation, lazy=False,
cascade="save-update"),
}
)
purchaseRequisition_mapper = bind_mapper( app_model.PurchaseRequisition,
app_schema.PurchaseRequisitionTable,
properties={
'purchaseRequisitionBudgetCostCenter' :
relation(app_model.PRBudgetCostCenterAssociation, lazy=False,
cascade="save-update"),
})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---