Welcome Guest, Not a member yet? Register   Sign In
Model Design Question
#7

(This post was last modified: 12-16-2019, 12:41 AM by IVIike.)

@MGatner:

Here is my abstract class:
PHP Code:
<?php

namespace App\Models;

class 
AbstractClass
{
    private $pId 0;
    private $name "";
    protected $table "parent";

    /**
     * @return int
     */
    public function getPId(): int
    
{
        return $this->pId;
    }

    /**
     * @param int $pId
     */
    public function setPId(int $pId): void
    
{
        $this->pId $pId;
    }

    /**
     * @return string
     */
    public function getName(): string
    
{
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name): void
    
{
        $this->name $name;
    }

and my child class:
PHP Code:
<?php

namespace App\Models;

class 
SubClass extends AbstractClass
{
    protected $table "child";
    private $subvar "";
    private $f_parent 0;
    private $cId 0;

    /**
     * @return int
     */
    public function getCId(): int
    
{
        return $this->cId;
    }

    /**
     * @param int $cId
     */
    public function setCId(int $cId): void
    
{
        $this->cId $cId;
    }


    /**
     * @return string
     */
    public function getSubvar(): string
    
{
        return $this->subvar;
    }

    /**
     * @param string $subvar
     */
    public function setSubvar(string $subvar): void
    
{
        $this->subvar $subvar;
    }

    /**
     * @return int
     */
    public function getFParent(): int
    
{
        return $this->f_parent;
    }

    /**
     * @param int $f_parent
     */
    public function setFParent(int $f_parent): void
    
{
        $this->f_parent $f_parent;
    }


If I then load the child from the database only the child variables are set:

PHP Code:
$db = \Config\Database::connect();
$db1=$db->table($table);
$db1->join("parent""f_parent=pId");
$c $db1->get()->getCustomResultObject(SubClass::class);

array(
1) {
  [0]=>
  object(App\Models\SubClass)#76 (8) {
    ["table":protected]=>
    string(5"child"
    ["subvar":"App\Models\SubClass":private]=>
    string(5"child"
    ["f_parent":"App\Models\SubClass":private]=>
    string(1"1"
    ["cId":"App\Models\SubClass":private]=>
    string(1"1"
    ["pId":"App\Models\AbstractClass":private]=>
    int(0)
    ["name":"App\Models\AbstractClass":private]=>
    string(0""
    ["pId"]=>
    string(1"1"
    ["name"]=>
    string(6"Parent"
  }

Reply


Messages In This Thread
Model Design Question - by IVIike - 12-11-2019, 06:16 AM
RE: Model Design Question - by vincent78 - 12-11-2019, 11:37 AM
RE: Model Design Question - by IVIike - 12-13-2019, 03:06 AM
RE: Model Design Question - by MGatner - 12-13-2019, 03:59 PM
RE: Model Design Question - by vincent78 - 12-13-2019, 04:47 PM
RE: Model Design Question - by MGatner - 12-14-2019, 05:34 AM
RE: Model Design Question - by IVIike - 12-16-2019, 12:40 AM
RE: Model Design Question - by MGatner - 12-20-2019, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB