CodeIgniter Forums
Relation entity - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Relation entity (/showthread.php?tid=75099)



Relation entity - mcachile - 12-20-2019

Hello! I am from Argentina. Sorry for my bad English.   

I have a simple entity:

PHP Code:
<?php

namespace App\Entities;

class 
Usuario {

    protected $id;
    protected $nombre;
    protected $apellido;
    protected $fecha_nacimiento;
    protected $dni;
    protected $email;
    protected $imagen;
    protected $id_puesto;
    protected $id_area;
    protected $id_sector;
    protected $session_id;
    protected $is_su;
    protected $limitar_cajas;
    protected $habilitado;
    protected $password;
    protected $defecto;
    protected $fecha_alta;

    public function __set(string $key$value null) {
        $method 'set' ucwords($key);
        if (method_exists($this$method)) {
            $this->$method($value);
        } else if (isset($this->$key)) {
            $this->$key $value;
        }
    }

    public function __get(string $key) {
        $method 'get' ucwords($key);
        if (method_exists($this$method)) {
            return $this->$method();
        } else if (isset($this->$key)) {
            return $this->$key;
        }
    }



This entity is associated with a user model.

My question is: How do I communicate, for example, id_area with your table? The desired result would be:

$user->area->name or $user->area->id.

Thanks.


RE: Relation entity - MGatner - 12-21-2019

CodeIgniter does not have built-in Object Relation Mapping so you will either need to do this yourself or use a module that adds that functionality (https://github.com/tattersoftware/codeigniter4-relations, https://forum.codeigniter.com/thread-74863-post-369959.html#pid369959, https://github.com/yidas/codeigniter-model).