Attempt to fix dbjoin/CDD as repeatelement in joined group

http://fabrikar.com/forums/index.php?threads/problem-in-multi-select-dropdown-in-cascadingdropdwon-under-repeat-group.36065/

Did I really find a solution? This time for databasejoin only. 

Generally it seems to working fine. Except 2 bugs (not sure is it caused by my fix or by something else):

1) I can't delete the single repeat group when min repeats is not set. 
When I set min repeats to 0 then I can do it (group is deleted) but I receive also a message:
Unknown column 'Array' in 'where clause' SQL=DELETE FROM chb_test_2013_repeat_checkboxes_2013 WHERE parent_id = Array

2) Another, not very important bug - in new repeat group the same checkboxes are checked as in the first group. Unchecking them, checking needed boxes and saving it - all works. 

3) NEW - test result for CDD shows that changes in databasejoin.php affected this element as well - that means it works. BUT the issue with deletion of single repeat group remains even if I set min repeats to 0 and remove data from watched element. 

---------------------------------------------------------------
TODO - same solution for fileupload element. 
First testing has shown that it ALMOST works when being in nonrepeated joined group. The parent_id value in AJAX file upload table is then the pk of joined group BUT... there is only one row althought I tried to upload multiple files and 'null' is written in file field. And the files were not uploaded at all. No idea where could I find the code to change as I did for dbjoin. 
I think line 845 needs some explanation. In some circumstances F form/details view with dbjoin and cdd as checkboxes generated an incorrect query where IN statement was without any data - IN() or with persistent empty data - like IN('65',,'66'). 
$vchild = $db->quote($vchild) just didn't help. All this occurred namely when the watched element was also a dbj or cdd in checkbox mode and empty when form was loaded.