Welcome, Guest
Username: Password: Remember me

TOPIC:

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
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 ???

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

Last edit: by dyvel.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
Just to be 100% clear, then I'm working in frontend on an item

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

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

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

definitivly.

EDIT : so you must write it in the front item model.
Coding is now a piece of cake

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

Last edit: by admin.

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
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)

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

Last edit: by dyvel.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
ok... I won't touch RUN now :)

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

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

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

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

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

Now I can get some sleep tonight :D

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

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

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

You are welcome.
Coding is now a piece of cake

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

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

  • BTB300
  • BTB300's Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 415
  • Thank you received: 132
I think Admin wins the prize! (Always willing to help us)

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

Last edit: by BTB300.

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

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

Next time, I will let you search a little bit and let you the prize !!
Coding is now a piece of cake

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

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

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11

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?

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

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

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

EDIT : If you are using Authoring functionalities, they will be handled ;-)
Coding is now a piece of cake

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

Last edit: by admin.
Time to create page: 0.088 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