The new ability to export objects from joined tables is awesome! But it would be even more awesome if we could support exporting objects which joins a one-to-many relationship table.
I found that it's not that hard to do this. The only API addition we need is that each join that is a one-to-many relationship needs to define array_key like this:
'join' => array(
'term' => array(
'table' => 'ctools_plugin_example_object_term',
'left_key' => 'oid',
'right_key' => 'oid',
// One-to-many relationships must define 'array_key'. Can be either
// EXPORT_NUMERIC_ARRAY or a field name from the joined table.
'array_key' => EXPORT_NUMERIC_ARRAY,
'load' => array(
'name',
'synonym',
),
),
),
The export should then look something like this:
$object = new stdClass;
$object->disabled = FALSE; /* Edit this to true to make a default object disabled initially */
$object->api_version = 1;
$object->machine_name = 'example';
$object->title = 'Example';
$object->body = 'Hello world';
$term = new stdClass;
$term->name = 'Lorem';
$term->synonym = '';
$object->term[] = $term;
$term = new stdClass;
$term->name = 'Ipsum';
$term->synonym = '';
$object->term[] = $term;
The join key is used as the identifier for child objects ($term).
Attached is two patches. One with only the API addition and one that adds an example module implementing this and an export_ui plugin. The example module is working, but not at all complete. Just so you can take a look at it.
Comments
Comment #1
dixon_Ping.
Comment #2
Bastlynn commentedAny chance of this getting added?
Comment #3
Bastlynn commentedSee #1365282: Documentation for Many to One Table Relationships for a follow up.
Comment #4
japerryDrupal 7 is no longer supported, closing.