I'm noticing strange behavior with Editor 1.6.1 for PHP. When I set up my PHP script to process the Editor, I only see some values being returned in the table. They happen to be only the varchar fields from the table. All integer and char fields are returning as NULL in the debug console. I have another Datatable displaying integer values just fine. After troubleshooting everything including leftJoins, where clause, and commenting out individual fields one by one, I determined that the issue seemed to lie with the table name.
Here is a bit about my setup: I'm using SQL Server 2012 R2 as the database back-end, PHP 5.4.16 running on Apache 2.4.6. Also using Bootstrap 3.3.7 and jQuery 3.1.0 scripts, but I imagine that doesn't matter much in this case. I just want to provide a complete picture to my environment.
I'll provide my server-side code to give an idea of what works and what doesn't:
This works but integer and char fields return as null values (data is actually not returned from the DB, it's not just missing from the table):
Editor::inst( $db, 'dynamic_sku_config, 'id' )
->fields(
Field::inst( 'dynamic_sku_config.product_family_id' )
->options( Options::inst()
->table( 'product_family' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'dynamic_sku_config.component_type_id' )
->options( Options::inst()
->table( 'component_type' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'dynamic_sku_config.ordinal_position' ),
Field::inst( 'dynamic_sku_config.following_delimiter' ),
Field::inst( 'dynamic_sku_config.min_components' ),
Field::inst( 'dynamic_sku_config.max_components' ),
Field::inst( 'dynamic_sku_config.action' ),
Field::inst( 'product_family.name' ),
Field::inst( 'component_type.name' )
)
->leftJoin( 'product_family', 'product_family.id', '=', 'dynamic_sku_config.product_family_id' )
->leftJoin( 'component_type', 'component_type.id', '=', 'dynamic_sku_config.component_type_id' )
->where( 'dynamic_sku_config.product_family_id', $_POST['selectedProductFamily'], '=' )
->process( $_POST )
->json();
In the above example, here are the database field types (each table has a field named "id" as an integer primary key):
dynamic_sku_config
product_family_id, int
component_type_id, int
ordinal_position, int
following_delimiter, char(1)
min_components, int
max_components, int
action, varchar(16)
component_type
name, varchar(50)
product_family
name, varchar(50)
Interestingly, since I'm joining to other tables for product_family and component_type, the Datatable will display the name field from the joined tables (product_family_id and component_type_id are not displayed to the user). The action field is also displayed as it is varchar. Every other field is blank due to null values coming back from the server.
I copied the contents of dynamic_sku_config into another table called dskutest. Here is the modified code (identical to above except for the table name):
Editor::inst( $db, 'dskutest', 'id' )
->fields(
Field::inst( 'dskutest.product_family_id' )
->options( Options::inst()
->table( 'product_family' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'dskutest.component_type_id' )
->options( Options::inst()
->table( 'component_type' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'dskutest.ordinal_position' ),
Field::inst( 'dskutest.following_delimiter' ),
Field::inst( 'dskutest.min_components' ),
Field::inst( 'dskutest.max_components' ),
Field::inst( 'dskutest.action' ),
Field::inst( 'product_family.name' ),
Field::inst( 'component_type.name' )
)
->leftJoin( 'product_family', 'product_family.id', '=', 'dskutest.product_family_id' )
->leftJoin( 'component_type', 'component_type.id', '=', 'dskutest.component_type_id' )
->where( 'dskutest.product_family_id', $_POST['selectedProductFamily'], '=' )
->process( $_POST )
->json();
All fields are now populating in the Datatable with no changes to the front-end page. I should point out that tables with a single underscore in them (e.g., product_family, component_type, etc.) work without issue. I hadn't captured the actual query being sent to the SQL Server but I could probably get it if it would be of interest or provide any clues as to why this might be happening.
I didn't see anyone else with this same issue on the forums, so I thought I would post it myself, either as a workaround for anyone encountering the same issue (or maybe a bug fix for a future release!).