~coughphp/coughphp/2.0

« back to all changes in this revision

Viewing changes to design/AddingFromOneCollectionToAnother.markdown

  • Committer: Anthony Bush
  • Date: 2008-08-23 03:35:08 UTC
  • mfrom: (262.1.18 coughphp-release-1.3)
  • Revision ID: anthony@anthonybush.com-20080823033508-uy4yn5pmio6wcetv
Accept release-1.3 branch changes into trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
$orderB->addOrderLine($orderA->getOrderLine_Collection());
4
 
// Besides the fact that this won't work in the new Cough because add requires that you add an individual element, the idea here is that all the order line objects for one collection should be nulled out during the add process and they should be updated to the with order id = $orderB->getOrderID() when orderB is saved. The latter part is done already, but the first part (nulling out) is not.
5
 
 
6
 
// Rather than re-add all the crazy functions required to make adding multiple elements in the same function call work, we should require that the Cough user provide their own loop:
7
 
 
8
 
foreach ($orderA->getOrderLine_Collection() as $orderLine) {
9
 
        $orderB->addOrderLine($orderLine);
10
 
}
11
 
$orderB->save();
12
 
 
13
 
// Doing this is not "extra" work for the Cough user because it is clearer "addOrderLine" is not plural and thus should suggest that you can't add a collection, you have to do the loop yourself. The fact that Cough users everywhere get to benifit from a lighterweight ORM is a side-effect.
14
 
 
15
 
 
16
 
 
17
 
// CURRENT WORKAROUND
18
 
// The current workaround is so simple it makes me wonder if it is even a work around. All we do is null out the order id before adding it to the new order line. One might argue that makes more sense, as adding directly from one to the other is ambigous (i.e. an order line can only have one order, so is adding it to this new order supposed to remove it from the old one or should I have to explicitily do it?
19
 
 
20
 
foreach ($orderA->getOrderLine_Collection() as $orderLine) {
21
 
        $orderLine->setOrderId(null);
22
 
        $orderB->addOrderLine($orderLine);
23
 
}
24
 
$orderB->save();
25
 
 
26
 
 
27
 
 
28
 
?>
 
 
b'\\ No newline at end of file'