if ($fkClass) {
$tableName = AllCoreTables::getTableForClass($fkClass);
$fkKey = $data['FKKeyColumn'] ?? 'id';
- // Backward-compatibility for older api calls using e.g. "contact" instead of "contact_id"
- if (strpos($field, '_id')) {
- $alias = str_replace('_id', '', $field);
- $joinable = new Joinable($tableName, $fkKey, $alias);
- $joinable->setJoinType($joinable::JOIN_TYPE_MANY_TO_ONE);
- $joinable->setDeprecated();
- $table->addTableLink($field, $joinable);
- }
$joinable = new Joinable($tableName, $fkKey, $field);
$joinable->setJoinType($joinable::JOIN_TYPE_MANY_TO_ONE);
$table->addTableLink($field, $joinable);
$this->assertEquals('TesterCo', $emailGet['contact_id.employer_id.display_name']);
}
- public function testDeprecatedJoins() {
- $message = '';
- try {
- \Civi\Api4\Email::get(FALSE)
- ->addWhere('contact.first_name', '=', 'Peter')
- ->addWhere('contact.last_name', '=', '')
- ->addWhere('contact.is_deleted', '=', 0)
- ->addWhere('contact.is_deceased', '=', 0)
- ->addWhere('email', '=', '')
- ->addWhere('is_primary', '=', TRUE)
- ->setSelect(['contact_id'])->execute();
- }
- catch (\Exception $e) {
- $message = $e->getMessage();
- }
- $this->assertStringContainsString("Deprecated join alias 'contact' used in APIv4 get. Should be changed to 'contact_id'", $message);
- }
-
public function testJoinWithExpression() {
$contact1 = $this->createTestRecord('Contact');