Note that there are some explanatory texts on larger screens.

plurals
  1. POAm I doing Doctrine subclasses correctly? Why the Error?
    primarykey
    data
    text
    <p>I started to build a POS system in Doctrine. I am getting an order, but I have no clue whether or not I even set up subclasses in the proper way for Doctrine.</p> <p>Here is the model I came up with for line items on an order</p> <pre><code>lineItem: line_total, order_id, type rentLineItem: returned_date_time, item_id, sold buyLineItem: item_id </code></pre> <p>The database looks like that. Type is either a 1 (rent) or a 2 (buy)</p> <p>Here is the lineItem class</p> <pre><code>class lineItem extends Doctrine_Record { public function setTableDefinition() { $this-&gt;hasColumn('line_total','int'); $this-&gt;hasColumn('order_id','int'); $this-&gt;setSubclasses(array( 'rentLineItem' =&gt; array('type' =&gt; 1), 'buyLineItem' =&gt; array('type' =&gt; 2), ) ); } public function setUp() { $this-&gt;hasOne('order', array('local' =&gt; 'order_id', 'foreign' =&gt; 'id')); } } </code></pre> <p>Here is the rentLineItem class (buyLineItem looks similar)</p> <pre><code>class rentLineItem extends lineItem { public function setTableDefinition() { $this-&gt;hasColumn('returned_date_time','datetime'); $this-&gt;hasColumn('sold','tinyint', 2); // just in case it is sold at the end of the rental $this-&gt;hasColumn('item_id','int'); } public function setUp() { $this-&gt;hasOne('item', array('local' =&gt; 'item_id', 'foreign' =&gt; 'id')); } } </code></pre> <p>Here is the code I have calling the objects</p> <pre><code>$q = Doctrine_Query::create() -&gt;select('*') -&gt;from('order') -&gt;where('DATE(creation_date_time) = \'' . $theDate . '\''); $orders = $q-&gt;execute(); $totalRents = 0; $totalSales = 0; foreach ($orders as $order) { foreach ($order-&gt;line_items as $lineItem) { if ($lineItem-&gt;type == 1) { $totalRents++; } else if ($lineItem-&gt;type == 2) { $totalSales++; } } } </code></pre> <p>Here is the error I am getting</p> <pre><code>Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property / related component "type" on "lineItem"' in /Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php:55 Stack trace: #0 /Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record.php(1296): Doctrine_Record_Filter_Standard-&gt;filterGet(Object(lLineItem), 'type') #1 /Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record.php(1255): Doctrine_Record-&gt;_get('type', true) #2 /Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Access.php(72): Doctrine_Record-&gt;get('type') #3 /Developer/Projects/VEL/manage/manage/dailyincomeexpensereport.php(29): Doctrine_Access-&gt;__get('type') #4 {main} thrown in /Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php on line 55 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload