Skip to content
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

Custom Foreign Key (Not Normalized Database Names) #282

Open
pdrappo opened this issue Dec 11, 2018 · 0 comments
Open

Custom Foreign Key (Not Normalized Database Names) #282

pdrappo opened this issue Dec 11, 2018 · 0 comments

Comments

@pdrappo
Copy link

pdrappo commented Dec 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant