ZF2 Mapper/ Multiple Tables Models

Home Forums Learn ZF2 ZF2 Mapper/ Multiple Tables Models

This topic contains 0 replies, has 1 voice, and was last updated by  dshukla@nexgenwireless.com 1 year, 11 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #764

    Hello,
    I am working on a query which has multiple joins (around 8 tables) and planning to create a model for it, but I don’t know the best way to go for it. For now I have created is a DBmapper class (also my service), which fills in my model.

    I am attaching the building blocks so you get an idea on how I am pursuing this. I want my model to refer other entities, but using a hydrator I am not able to achieve that. Like in my Model (client_id, client_name) can be one object ref ($_client) similarly for network. Group is its own model, but still I could not refer here in my model as my Hydrating result set works on only 1 db column at a time.

    Please let me know if there is a better way to do this, or to reference the different models in my attribute model, and to hydrate it.

    Thanks,
    Dhruv

    Here is the mapper Select SQL:
    $select = $this->getSql()->select()
    ->from(array(‘t1’ => new TableIdentifier(‘client_tb’, ‘system_info’)))
    ->columns(array(‘client_id’, ‘client_name’))
    ->join(array(‘t2’ => new TableIdentifier(‘network_tb’, ‘system_info’)),
    ‘t1.client_id = t2.client_id’,
    array(‘network_id’, ‘network_name’))
    ->join(array(‘t3’ => new TableIdentifier(‘atribte_group_tb’, ‘topo’)),
    ‘t2.network_id = t3.network_id’,
    array(‘atribte_group_id’, ‘atribte_group_name’))
    ->join(array(‘t4’ => new TableIdentifier(‘atribte_tb’, ‘topo’)),
    ‘t3.atribte_group_id = t4.atribte_group_id’,
    array(‘atribte_deflt_value’, ‘atribte_id’,’atribte_name’, ‘last_updt_ts’, ‘updt_user_id’))
    ->join(array(‘t5’ => new TableIdentifier(‘data_type_tb’, ‘system_info’)),
    ‘t4.atribte_data_type_id = t5.data_type_id’,
    array(‘data_type_id’, ‘data_type_name’))
    ->join(array(‘t6’ => new TableIdentifier(‘measure_unit_tb’, ‘system_info’)),
    ‘t4.measure_unit_id = t6.measure_unit_id’,
    array(‘measure_unit_id’, ‘measure_unit_name’), Select::JOIN_LEFT)
    ;
    return $select;

    Hydrator Being Used:
    if ($this->hydrator === null) {
    $this->hydrator = new ClassMethods();
    $this->hydrator->setNamingStrategy(new MapperNamingStrategy(
    $this->getHydratorMapping()
    ));
    //$this->hydrator = new AttributeHydrator($this->getHydratorMapping());
    }
    return $this->hydrator;

    Model Which exists as of now: (each property has getter and setters.)
    private $_id;
    private $_name;
    //private $_client; //key and value pair
    //private $_network; //key and value pair
    //private $_group;//key and value pair – Attribute Group Object

    private $_groupId;
    private $_groupName;
    private $_clientId;
    private $_clintName;
    private $_networkId;
    private $_networkName;

    private $_dataType;
    private $_defaultValue;
    private $_displayFormat;
    private $_unitOfMeasure;
    private $_enabled;
    private $_createdDate;
    private $_createdBy;
    private $_lastModifiedDate;
    private $_lastModifiedBy;

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.