Question

I am currently working an application with Code Igniter and Datamapper ORM and I am trying to save data in the database. I have two tables which have a many to many relationship between eachother. For example: ShoeDesigns and ShoePieces. I would also like to save some data in the join table between ShoeDesigns and ShoePieces i.e. ShoeDesigns_ShoePieces. I have tried to look around for examples but no luck.

I was just wondering if it is possible to actually do it and if I can do it in one save call or would I have to do it in multiple save calls?

Thanks guys.

Was it helpful?

Solution

If you added data to ShoeDesigns_ShoePieces other than that pertaining to the relationship between ShoeDesigns and ShoePieces, you would be violating the ORM concept. ShoeDesigns_ShoePieces would no longer only model a relationship, but it would be a hybrid between entity and relationship.

You need to do this if you have some attributes that attach to the relationship between ShoeDesigns and ShoePieces; and this means that the "relationship" is actually an entity.

Let us call it ShoeAssemblyPlan. Then you have:

  • a many-to-many relationship between ShoeDesigns and ShoeAssemblyPlan
  • a many-to-many relationship between ShoeAssemblyPlan and ShoePieces

(The relationships could also be many-to-one).

Your old relationship between Designs and Pieces is now realized through an Assembly Plan, to whom you can attach the attributes you desire.

For example you could have a "Glue Stacked Design to Four-Piece Set" assembly plan and a "Stitch Formal Design to Four-Piece Set" assembly plan; and you might have a different Cost and LeadTime associated to each plan.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top