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.169 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started