-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Description
Hi everyone, i looking for some help solving a problem using Spot2. I have working in a project who has a database already made. The fields of the tables are not normalized, so i'm not able or i can't figure it out how to make a relation between two tables.
I want to connect People with Cities:
class Persona extends \Spot\Entity
{
public static function fields()
{
return [
...
"PERSONA_Id" => ["type" => "integer", "unsigned" => true, "primary" => true, "autoincrement" => true],
"PERSONA_Nombre" => ["type" => "string", "length" => 255],
"CODIGOPOSTALES_Id" => ["type" => "string", "length" => 50],
...
];
}
public static function relations(Mapper $mapper, Entity $entity)
{
return [
'localidad' => $mapper->belongsTo($entity, 'App\Entities\Sga\CodLoc', 'CODIGOPOSTALES_Id')
];
}
}
class CodLoc extends \Spot\Entity
{
public static function fields()
{
return [
"id" => ["type" => "integer", "unsigned" => true, "primary" => true, "autoincrement" => true],
"CodLoc" => ["type" => "string", "length" => 5],
"DesLoc" => ["type" => "string", "length" => 250]
];
}
}
When i fetch Persona with Persona_Id i want to get the correspondig City when CODIGOPOSTALES_Id = DesLoc"
How can i do this??
Thanks
Metadata
Metadata
Assignees
Labels
No labels