-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIv4 - Rename id_field to primary_key and make it an array #20749
Conversation
(Standard links)
|
@eileenmcnaughton after applying this try regenerating the DAO for your special entity and it should get the new value. |
@eileenmcnaughton @seamuslee001 @totten per our discussion. |
These are from chat on mattermost - just adding them here for the record Hmm ok - so I just tested by
civicrm/admin/search#/create/Contact?params=%7B"version":4,"select":%5B"id","display_name","Contact_MailingProviderData_contact_id_01.mailing_identifier"%5D,"orderBy":%7B%7D,"where":%5B%5D,"groupBy":%5B%5D,"join":%5B%5B"MailingProviderData%20AS%20Contact_MailingProviderData_contact_id_01","LEFT",%5B"id","%3D","Contact_MailingProviderData_contact_id_01.contact_id"%5D%5D%5D,"having":%5B%5D%7D I'm still getting this error Error: Call to a member function getEntityFields() on null in Civi\Api4\Query\Api4SelectQuery->autoJoinFK() Was the expectation that the generated primary key would be an array of the key fields rather than the name of it? https://github.com/eileenmcnaughton/org.wikimedia.omnimail/blob/master/CRM/Omnimail/DAO/MailingProviderData.php#L32 |
I tried updating to
and the error is the same - but I suspect the intent of the change is that ^^ should be generated. |
xml/templates/dao.tpl
Outdated
* | ||
* @var string[] | ||
*/ | ||
public static $_primaryKey = [{if $table.primary_key}'{"', '"|implode:$table.primary_key}'{/if}]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some entities have a combination of primary keys instead of a single field. This is allowed in the schema so the API needs to be able to handle it too. Renaming it for consistency with the schema.
Ok - this does make the agreed changes and correctly generates a primary key as an array and where a composite primary key can be generated - it doesn't get us to the point where the composite primary key is handled by the api layer fully but it is mergeable in itself at this stage |
Overview
Followup from #20707 - use an array for the identifier field because some tables have multiple primary keys.
Technical Details
This adds
$_primaryKey = ['id']
to DAOs (in the parentCRM_Core_DAO
class) and if any entity happens to have a different primary key or set of keys in its schema then GenCode will insert that value into its generated DAO class.APIv4 will pick up on this value and act appropriately, making use of the primary key data in its queries.