Module CustomFields Dev: Difference between revisions

Jump to navigation Jump to search
(→‎Input forms for custom fields: Added AJAX-PHP callback)
Line 350: Line 350:


Note: this method will always return an array of records object, for more consistency (and this is the main difference with fetch(null) ).
Note: this method will always return an array of records object, for more consistency (and this is the main difference with fetch(null) ).
=== Fetching referenced records of a constrained field ===
A constrained custom field points to another database table, and a value for this constrained field is the rowid of a record in the referenced table.
Thus, the principal purpose of a constrained custom field is not the value of the field in itself (it's simply an integer), but rather the other fields available from the referenced table, the constrained field being in fact just a pointer.
To fetch the remote record from the referenced table, use the fetchReferencedValuesList() of the CustomFields class:
<source lang="php">
$fkrecord = fetchReferencedValuesList($field, $id=null, $where=null, $allcolumns=false);
</source>
Where:
* $field is a custom field object (fetched using fetchFieldStruct() or fetchAllFieldsStruct()),
* $id is the rowid of the record to get, just like fetch() and fetchAll(). Can be null to fetch all remote records (or to use the $where clause).
* $where is a string without the WHERE clause (eg: "fk_facture=1") to get finer control. In this case, you can use $id or set $id=null depending on your purpose. This is mainly a private argument to allow for cascade option.
* $allcolumns if false, it will fetch only the required columns to do the smart value substitution. If true, it will fetch all remote columns (useful for ODT substitution). If an array of strings, each string will be a column to fetch from the remote database.
Note that this function is NOT recursive (it will fetch the records from the referenced table, and that's all, it won't fetch the custom fields of the referenced table nor recursively fetch the remote constrained custom fields). To do recursive fetching, see in the Facade API.


== Input forms for custom fields ==
== Input forms for custom fields ==
439

edits

Navigation menu