Primary key element is not available in data set
Primary key element is not available in data set

Hi!
The editor is defined like this :
$editor = Editor::inst( $db, 'table1', array('field1', 'field2') )
->fields(
Field::inst( 'table1.field1', 'field1'),
Field::inst( 'table1.field2', 'field2')
)
->leftJoin( 'table2', 'table2.field1', '=', 'table1.field1' )
->process( $_POST )
->data();
When i try to add a record i get this error Primary key element is not available in data set
If i define it like this :
$editor = Editor::inst( $db, 'table1', array('field1', 'field2') )
->fields(
Field::inst( 'table1.field1'),
Field::inst( 'table1.field2')
)
->leftJoin( 'table2', 'table2.field1', '=', 'table1.field1' )
->process( $_POST )
->data();
it works.
I would like to use field names not the table.field format
I don't want to use the actual database naming
How can i do this ?
I see that the error is generated in function pkeyToValue that calls function _readProp in witch you search the table name in an array of fields names.
This question has accepted answers - jump to:
Answers
That's a good question - I don't think we've come across that before or tested for it. Are you submitting the fields without the table names when using the second parameter for the
Field
instance?Allan
I would of thought this would be the setup as you already defined table1 after $db
@allan
i submit the fields without table name. The editor looks like this :
I do this because
if the PHP API is like this (the way i want - with table name hidden)
and i edit the editor to include the table name
so the editor will submit the table name
i get this error:
Thank you. If you are using:
then on the client-side you should just use
name: 'field1'
since the second parameter forField::inst()
sets the JSON / HTTP variable name.Allan
Well @allan that's the problem ... i can't use
name: 'field1'
for fields that are part of the primary key of the table when i have on server sideField::inst( 'table1.field1', 'field1')
because i receive the errorPrimary key element is not available in data set
For primary keys i have to use
name: 'table1.field1'
because of how function _readProp from PHP API handles this situationFor other fields ( not primary keys ) it works - i can use
name: 'field3'
Sorry - I didn't quite connect all the dots. I agree - that looks wrong. I've filed a bug report in our internal tracker to have this addressed (if it can be without backwards compatibility issues) for 1.9.1.
Allan
Thank you
I've just been looking into this and I fear that I don't see a good way to handle this in the code. The main issue is that if you are using a join, Editor will automatically prefix the table names to the primary key column names in order to ensure there are no clashes with the joined table(s).
That's okay on read, but a problem on write since
pkeyToValue
is looking at the array of data the client submitted, rather than one translated from the client submission into the db parameters.It possibly should do that and I'm keeping this issue open internally, but I'm concerned that its going to take a fair amount of development time to do when there is a reliable workaround - not using the http alias.
Allan