Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

ORM calling another table within a view 23 Jul 2019 19:00 #15759

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I am using a view / layout of film.monetize
In the old version of JCook, before ORM I used to do this to call data from another table on the fly
$modelContracts = CkJModel::getInstance('contracts', 'MyComponentModel');
$modelContracts->setState('context', 'contracts.monetize');
switch ($this->item->type) {
    case "1":
        $modelContracts->addWhere('a.films = 1');
        break;
    case "2":
        $modelContracts->addWhere('a.shorts = 1');
        break;
    case "3":
        $modelContracts->addWhere('a.series = 1');
        break;
    default:
        break;
}

$modelContracts->addSelect('(select count(*) FROM #__mycomponent_xtitlecontracts WHERE contract=a.id AND title=' . $_GET['id'] . ') as count');
$modelContracts->addSelect('(select b.id FROM #__mycomponent_xtitlecontracts AS b WHERE b.contract=a.id AND b.title=' . $_GET['id'] . ' LIMIT 1) as linkID');
$modelContracts->addSelect('(select c.payment_status FROM #__mycomponent_xtitlecontracts AS c WHERE c.contract=a.id AND c.title=' . $_GET['id'] . ' LIMIT 1) as paymentStatus');
$modelContracts->addWhere('a.published = 1');
$modelContracts->addOrder('a.contract_name');

$contracts = $modelContracts->getItems();

I am now in the process of converting one of my largest components to ORM and I have ZERO clue how to get started on this.
I have written the model for contracts.monetize no problem bit now I need to call this data from another view

As I starting point to just pulling in the WHOLE model I did
$modelContracts->orm(array(
            'context' => 'contracts.monetize'
        ));

but I get

Call to a member function orm() on null

Any tips to getting started are appreciated as the documentation doesnt quite have the situtaiton, and the only help I found in the forum was using an instance getData which I cant find in the documentation
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

ORM calling another table within a view 24 Jul 2019 14:30 #15760

Before calling you still use
$modelContracts = CkJModel::getInstance('contracts', 'MyComponentModel');
I assume?

You can achieve your query with orm also like this (just typing this as I go so there might me errors)L
$filter = array(
    'published' => array(
        'value' => 1
    )
);
switch ($this->item->type) {
    case "1":
        $filter['films'] = array('value' => 1);
        break;
    case "2":
        $filter['shorts'] = array('value' => 1);
        break;
    case "3":
        $filter['series'] = array('value' => 1);
        break;
    default:
        break;
}

$contracts = MyComponentHelper::getData('contracts',
  array(
    'context' => 'contracts.monetize',
    'filter' => array(
        $filter
    ),
    'order' => array(
        'contract_name' => ASC
    )
));

This misses the subselect count(*), but I have created a solution somewhere. Have to look that up :D
The following user(s) said Thank You: MorganL

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.085 seconds

The j-cook project is one of the best of its kind and it is nice that we all try to contribute in little ways to make life easy for each other.

vlemos (Forum)  

Get Started