database - CakePHP: Unsure how to handle a semi difficult relationship -
i'm working on first cakephp app, order/invoice system. order-part coming along nicely, invoices kinda need help.
the database structure i'm using; delivery note consists of multiple products, in turn exist of multiple re-usable elements (like number of trays , product itself). because customer order larger quantities, lower rates, time-based (from week 1 9 €1 element y, , week 10 8 €1.20 same element). of course customers have use daily prices, stored same way, witha nulled customer_id.
now problem; have absolutely no idea how should tackle invoice view, or more specifically; best way data, or if should go , practice sql-writing skills.
i'm not seeing major problems schema. containable behavior should make things easy here. add invoice model:
var $actsas = array('containable'); make life easier adding defaultprice relationship each element. in element model:
var $hasone = array( 'defaultprice' => array( 'classname' => 'price', 'foreignkey' => 'element_id', 'conditions' => array('defaultprice.customer_id null') ) ); now build invoice, set , pass contain parameter find operation. (i assume want show breakdown of element costs, right?)
$contain = array( 'deliverynote' => array( 'product' => array( 'element' => array( 'defaultprice', 'price' => array( 'conditions' => array('price.customer_id' => $customer_id) ) ) ) ) ); $this->invoice->find('first', array('conditions' => ..., 'contain' => $contain)); this should result in each element record including defaultprice, , if customer receiving special pricing, price record included.
note: may want consider including default_price field in element field, , avoid having additional join above. every element going have default price, right?
Comments
Post a Comment