PDOException using ->join

PDOException using ->join

iain_mciain_mc Posts: 15Questions: 0Answers: 0
edited January 2013 in Editor
Of course, I could be doing it wrong as this is first time I've attempted to use a Join but I've tried to follow your examples. Seems to be looking for an array where it expects a column.

I'd just like the joined data for display and search, it doesn't need to be actually edited like the primary fields.

[code]
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status_reporting.Array' in 'field list'' in /blah/system/dataTables/Database/Driver/Mysql/Query.php:98
[/code]

Tables are:

status_reporting (containing field rock_id, which I wish to join to the child's "id" field)
big_rocks (child, keyed on "id")

Code looks like this:

[code]
require_once( "../system/dataTables/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;

Editor::inst( $db, 'status_reporting' )
->field(
Field::inst( 'action_date' ) ->validator( 'Validate::dateFormat', 'Y-m-d' ),
Field::inst( 'rock_id' ) ->validator( 'Validate::required' ),
Field::inst( 'author_id' ) ->validator( 'Validate::required' ),
Field::inst( 'state' ),
Field::inst( 'thecomment' ) ->validator( 'Validate::required' )
)
->join(
Join::inst( 'big_rocks', 'object' )
->join(
array( 'rock_id', 'id' )
)
->field(
Field::inst( 'team_id' )
)
)
->process( $_POST )
->json();
[/code]

Many thanks for any response, it'd be great to get this working to save me having loads of reference arrays in JavaScript.

Iain

Replies

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    > I'd just like the joined data for display and search, it doesn't need to be actually edited like the primary fields.

    For this you can use the Join class's `set` method - http://editor.datatables.net/docs/current/php/class-DataTables.Editor.Join.html#_set . Add `->set( false )` to your Join instance and DataTables will effectively ignore it on create and edit.

    I think the problem you are seeing here is that for a simple join such as you want here, give the fields for Join as two strings, rather than an array: `->join( 'rock_id', 'id' )` .

    The `join` method is a a bit of a tricky one in that regard as it needs to be flexible enough to cope with the different options available for the join action. I wonder in future if I should have `joinField` and `joinTable` methods instead of just `join` . I'll keep it in mind.

    Until then you might find the Join tutorial useful: http://editor.datatables.net/tutorials/php_join - particularly the second with the four example uses of `join` ("1. Single / Direct reference" etc).

    Regards,
    Allan
  • iain_mciain_mc Posts: 15Questions: 0Answers: 0
    Thanks Allan, that fixed the issue (using two strings rather than an array):

    [code]->join( 'rock_id', 'id' ) [/code]

    Cheers!

    Iain
This discussion has been closed.