Model join bug when update

38 views
Skip to first unread message

Gowrav Vishwakarma

unread,
Nov 26, 2012, 3:47:48 AM11/26/12
to agile-too...@googlegroups.com
reconstruct Bug:
1) In a model apply join
2) Add a field from that join table
3) Apply any condition on this joined field

When this model is applied to crud the selection goes very well with the condition

Adding data is also OKEY (not tested deeply)

But when editing such a record. this condition on model is left and all records without condition joined with first table are updated with edited values ...



example ::

<?php
class Model_Scholars_Current extends Model_Scholar{

    function init(){
        parent::init();
       
        $st = $this->join('student.scholar_id');
        $st->hasOne('Class', 'class_id');
        $st->addField('ishostler')->type('boolean');
        $st->addField('isScholared')->type('boolean')->caption('Hostler As Scholared');
        $st->addField('bpl')->type('boolean')->caption('BPL');
        $st->hasOne('Sessions_Current', 'session_id');

        $this->addCondition('session_id', $this->add('Model_Sessions_Current')->tryLoadAny()->get('id'));
       
    }
}

condition in bold is left when editing/updating

Romans Malinovskis

unread,
Nov 26, 2012, 4:47:04 AM11/26/12
to agile-too...@googlegroups.com
Hi Gowrav.

Yes, the condition is lifted when saving, because it’s producing errors otherwise, but:

1) we know the ID of the record, which was loaded with condition, so we are safe to edit it,
2) after model is saved, it attempts to reload the model with same ID, if condition is not matched, the transaction is rolled back.

I don’t understand how your example links to what you write about condition. 


(btw you could do this:

        $this->addCondition(‘session_id’, $this->add(‘Model_Sessions_Current’)->fieldExpr(‘id’));

--
 
 

--
Join our IRC Support channel: http://irc.lc/freenode/atk4 or irc://irc.freenode.net/atk4 

Romans Malinovskis is the author of the revolutionary PHP Framework: the “Agile Toolkit” (www.agiletoolkit.org). Please show your support by raising awareness about Agile Toolkit.

If you need help with your commercial Agile Toolkit project, consider using our dev team: http://www.agiletech.ie/company/

Gowrav Vishwakarma

unread,
Nov 26, 2012, 7:30:22 AM11/26/12
to agile-too...@googlegroups.com
In the example

1) one scholar has many student entries
2) each student entry has session_id field (out of them only one session is current at a time) and class_id field
3) When updating class of particular scholar joined with student with current session(out of so many student entries for that scholar) since condition is omitted it updates class_id of all students of that scholar while it should update only student with perticular session_id (Which one is marked as current in session table)

the update query is just like
UPDATE student SET class_id=17 where scholar_id=15 (checked via update)

while it should be
UPDATE scholar join student .. SET student.class_id=17 WHERE scholar.id=15 and student.session_id=8

like it is working for select.



--
 
 



--
Regards

Gowrav Vishwakarma
Man of Affairs, Digital Vish, Xavoc International
http://www.digitlavish.com : +91 9783807100
http://www.xavoc.com

--------------------------------------------------------------------
Never Never Never Never Never Never Never Never Never Never Never Never Never Never Never  GIVE UP
Reply all
Reply to author
Forward
0 new messages