-1

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.

koramaiku
  • 358
  • 2
  • 5
  • 22

1 Answers1

2

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.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • 1
    @Isemi Thanks for clarifying what I was trying to do, with the question. At least someone is out there willing to clarify if I was taking the wrong approach, instead of down voting my question. I understand the people at stack overflow are trying to maintain the quality of the site by monitoring questions, but I was actually trying to ask a legitimate question to find out what I am doing wrong as well as providing a sanity check for myself. I appreciate your effort. Thanks. – koramaiku Nov 15 '12 at 06:43