MODX Community

Error "No foreign definition" using getOne() for custom database

Hi all,
I don’t know what I’m miising but I couldn’t use getOne() with my custom DB
Here are the relevant lines ofmy schema:

<object class="Socios" table="socios" extends="xPDOSimpleObject">
	<field key="carsocio" dbtype="int" precision="2" phptype="integer" null="false" />

	<aggregate alias="miCarSocio" class="Carsocio" local="carsocio" foreign="id" cardinality="one" owner="foreign" />
<object class="Carsocio" table="carsocio" extends="xPDOSimpleObject">
	<field key="nombre" dbtype="char" precision="15" phptype="string" null="false" />

	<composite alias="misSocios" class="Socios" local="id" foreign="carsocio" cardinality="many" owner="local" />

Here’s t he php:

But it produces this error:

    [2020-03-31 23:26:48] (ERROR @ /home/ach/public_html/gpatax/core/xpdo/xpdo.class.php : 1826) No foreign key definition for parentClass: Socios using relation alias: miCarsocio

Any idea what could I be missing?

as a workaround I did this manualy with the following code:

$carsocio_id=$socio->get('carsocio');   //One('miCarsocio')->get('nombre');
$carsocio = $modx->getObject('Carsocio',$carsocio_id)->get('nombre');

It works,though I don’t know about its effíciency when it wíll need to deal with just a few reco rds as now

Anyway, I’d prefer the native solution, easier to read and less prone to errors…
Could anyone see what could I be missing?

miCarsocio in the getOne call, should be miCarSocio based on the alias in your schema.

Thank you very much Mark!!
I guess how could I have been missing that!

1 Like