Welcome, Guest
Username: Password: Remember me

TOPIC: €25 for help:all records from related table @ item

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:33 #3812

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
I'm a little confused by your code above.

echo("<pre>"); print_r($modelFoodbudgets); echo("</pre>"); // DBG temp VAR DUMP

echo("<pre>"); print_r($item); echo("</pre>"); // DBG temp VAR DUMP

dumps nothing - tried it in model and in fly page. Not sure if I'm doing something wrong. :dry:

should $item not be $this->item ???
Last Edit: 20 Sep 2012 15:34 by dyvel.
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:36 #3813

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
In an item template:
$this->item

In a list template :
$row

;-)

Very important, you must respect the correct model side (front / back). Because it is separated.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:38 #3814

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Just to be 100% clear, then I'm working in frontend on an item
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:38 #3815

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
FRONT / BACK

definitivly.

EDIT : so you must write it in the front item model.
Coding is now a piece of cake
Last Edit: 20 Sep 2012 15:40 by admin.
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:50 #3816

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
If you prefer to test your self, then please look in sandbox: sandbox.cms25.j-cook.pro/index.php?optio...et&layout=budget&cid[]=2

This is a budget item, where I'd like to display "sub budgets" that reference the budget item (food budget being one of them)
Last Edit: 20 Sep 2012 15:51 by dyvel.
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:54 #3817

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Ok, so do not touch the sandbox, I will exeptionaly write in it and show you.

You can play and prepare datas in it if you want, but DO NOT RUN in sandbox.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 15:56 #3818

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
ok... I won't touch RUN now :)
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 16:09 #3819

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
I found.

If you are not in a form, it is missing something I will fix.


In the classes/jmodel.item.php :
function getItem() ;

after :
$this->populateParams($data);
add :
$this->populateObjects($data);

I try to show you in sandbox.
Try by your side as well.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 16:16 #3820

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Available in sandbox.

Fixed issue.
You can apply the patch I told you before, or upgrade classes/jmodel.item.php

I got to go now.

You know my PayPal, right ? ;-)

Have a good evening.
Happy to help you.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 16:23 #3822

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
Got it working in my end as well
Thanks!!!!

Now I can get some sleep tonight :D
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 20 Sep 2012 16:46 #3826

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Received.

You are welcome.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 21 Sep 2012 14:08 #3831

  • BTB300
  • BTB300's Avatar
  • Online
  • Moderator
  • Posts: 414
  • Thank you received: 130
  • Karma: 46
I think Admin wins the prize! (Always willing to help us)
Last Edit: 21 Sep 2012 14:10 by BTB300.
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 21 Sep 2012 15:04 #3833

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Hard life.

Next time, I will let you search a little bit and let you the prize !!
Coding is now a piece of cake
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 26 Sep 2012 11:58 #4020

  • dyvel
  • dyvel's Avatar
  • Offline
  • Elite Member
  • Posts: 200
  • Thank you received: 11
  • Karma: 10
admin wrote:
Well,

You cannot implement it in your SQL query. You must have another call.
The only way to do it in one query, is to create a groupby on a food budget list. but is is limited to these page only, so it is a wrong way if you want to be free.

I think for you, below is the correct answer :
(It works on an ITEM model for the moment)

in your model, models/budget.php :

1. Create a new function : (copy / paste this)
public function populateObjects(&$item)
{
	$modelFoodbudgets = JModel::getInstance('Foodbudgets', 'BudgetsModel');
	$modelFoodbudgets->addWhere('a.budget = ' . (int)$item->id);
	$item->foodbudget = $modelFoodbudgets->getItems();
}

2.Test it

3 lines. That's it !

Note : The amazing stuff is that populateObject function is available in infinite cascads !
I mean if you add such code in your foodbudgets model to obtain another N:1 links, you will get them also from budgets model.

It is really easy.

So, please consider also if you always need theses items everytime you load a budget.
This solution I propose you will ALWAYS load the foodbudgets items, even when you open a page that do not need it.

If you want to restrict the loading of the N:1 items, use the states vars :

In our example, let's define a state namespace : 'objects.budgets'
public function populateObjects(&$item)
{
	if ($this->getState('objects.budgets'))	//Custom namespace here
	{
		$modelFoodbudgets = JModel::getInstance('Foodbudgets', 'BudgetsModel');
		$modelFoodbudgets->addWhere('a.budget = ' . (int)$item->id);
		$item->foodbudget = $modelFoodbudgets->getItems();
	}
}

And this in your view file BEFORE to load the items :
$state->set('objects.budgets', true); //ADD THIS
$this->item = $item = $this->get('Item');	//loads the Items, do not touch

Is there an easy way to load only published items?
The administrator has disabled public write access.

Re: €25 for help:all records from related table @ item 26 Sep 2012 12:02 #4021

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
$modelFoodbudgets->setState('filter.published', true);

EDIT : If you are using Authoring functionalities, they will be handled ;-)
Coding is now a piece of cake
Last Edit: 26 Sep 2012 12:03 by admin.
The administrator has disabled public write access.
Time to create page: 0.123 seconds

Get Started