atk4 / atk4-addons

Agile Toolkit Addons
http://atk4.com/
Other
15 stars 23 forks source link

id field especification for model with child tables. #29

Closed systamonster closed 11 years ago

systamonster commented 11 years ago

If the model have some child tables then table name must be espicicate for id field.

DarkSide666 commented 11 years ago

Not related with this issue, but just to let you know - it's not good to use getRows and get all rows parsed in some temporary variable. That takes much resources (like RAM and also execution speed).

Better approach is to use iterators and parse records one by one directly from database, like this:

$m_product = $this->add('Model_pageproduct')->addCondition('page_id', '1')->setOrder('ord');
foreach($m_product as $row){
    // Preferred: you can use $m_product as Model object which have 1 record loaded in it. In next iteration it'll be next record etc.
    if($m_product->isFoo()) echo 'Foo product: '.$m_product['name'];
    // Useful in some cases: you can use $row as a simple array (not object!) with current record data
    if($row['price']>100) echo 'Costly product: '.$row['price'];
    ...
}
systamonster commented 11 years ago

DarkSide666 thank you for your suggestion, I will try! Best regards, Kirill