In fact that was my initial question. But while trying to answer it I realised that I don't understand how database introspection strategy works even after reading docs on it.
Thus I need your help answering my questions:
1)I don't need to set introcpection strategy explicitely in services if I'm not going to cach model's metadata. It will be auto applied. Is that right?
2)Is this correct behaviour that all the fields have string data type in model when I'm getting database record?
object(CRM\Models\InvoiceItem)[98]
public 'id' => string '4' (length=1)
public 'invoice_id' => string '1' (length=1)
public 'part_id' => null
public 'part_number' => string 'QXXC324' (length=7)
public 'part_description' => string 'Some vendor crazy stuff server' (length=30)
public 'price' => string '20' (length=2)
public 'qty' => string '1' (length=1)
public 'discount' => string '0' (length=1)
public 'start_date' => string '2016-02-26 14:37:15' (length=19)
public 'end_date' => null
As I understand SQL column types are auto applied to model's fields in PDO when saving so It's possibly correct behaviour.
3)How to sanitize all the fields at once if I don't use Phalcon forms (I use custom datagrid).
For instance, I'm getting record for edit and assign it's new values from put array
$editItem = $cart -> getItems(['conditions'=>'id = :ed_id:','bind' => ['ed_id' => $editId]]) -> getFirst ();
$newValuesArr = $this -> request -> getPut();
$editItem -> assign($newValuesArr)
I get this:
object(CRM\Models\InvoiceItem)[98]
public 'id' => string '4' (length=1)
public 'invoice_id' => string '1' (length=1)
public 'part_id' => string '' (length=0)
public 'part_number' => string 'QXXC324' (length=7)
public 'part_description' => string 'Some vendor crazy stuff server' (length=30)
public 'price' => string '20' (length=2)
public 'qty' => string '5' (length=1)
public 'points' => string '0' (length=1)
public 'discount' => string '0' (length=1)
public 'start_date' => string '2016-02-26 14:37:15' (length=19)
public 'end_date' => string '' (length=0)
If I will save this record now I will get an error, because part_id has INT type in database.To avoid this I need(as I see it) to sanitize put values before or during the assignment to record.
I have a feeling that model's metadata->getDataTypes
should be utilized somehow.