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

TOPIC:

[SOLVED] AddWhere in Model Item 24 Nov 2012 07:38 #5629

Hello,

I am not sure if this is a big, but it is something I noticed in my generated code (so possibly it could be due to the configuration I had set up in the generator).

Anyway, I noticed that in the JModel.item.php class there is no function generated to add a where clause to the generated query (like there is in JModel.list.php). Of course this was easy to fix, by adding the following code to jmodel.item.php:
function addWhere($where_clause) {
	$this->_where[] = $where_clause;
}

I needed this to be able to filter data in some of the views.

Kind regards,

Misha

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

Re: AddWhere in Model Item 27 Nov 2012 07:40 #5651

  • BTB300
  • BTB300's Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 415
  • Thank you received: 132
Hi blue-canoe,

This was the same in cook 1.5 builds

as you suggested the solution is drop the function addWhere($where_clause){...} into the JModel.item.php

Then you can display item views based on such things as user by using addWhere() without having to display a collection view first something like
addWhere( $where[] = 'a.author = '.(int) $user->id;)

it could be due to the configuration I had set up in the generator).

www.j-cook.pro/forum/9-coding-inside-you...specific-record#2793
NOT relevant to Cook V2.0 (The Model Sql structure has changed drastically since then)
but it gives you some idea of what you "might need to do" if your still working with 1.5 builds

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

Last edit: by BTB300.

Re: AddWhere in Model Item 27 Nov 2012 09:47 #5655

  • BTB300
  • BTB300's Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 415
  • Thank you received: 132
Just Checked Cook V2.0
you dont need the addWhere() function in the jmodel.item.php
to limit data by multiple values
use something similar
//SELECT : raw complete query without joins
	$query->select('a.*');
	$query->where('a.id=1');
	$query->where('a.anotherfield=2');

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

Re: AddWhere in Model Item 27 Nov 2012 12:23 #5657

Thanks! That is good to know.

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

Re: AddWhere in Model Item 28 Nov 2012 12:34 #5667

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

AddWhere() is not available in item model. This is a choice to force you coding well.

Because ITEM is returning only one item, so you can never mix a filter on ID and something else.

in prepareQuery() :
- Create a new SQL context.
- Receive a customized state var.
- Filter on something else than ID, write your filter statement based on this received var.
Coding is now a piece of cake
The following user(s) said Thank You: BTB300

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

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

First of all... I have to congratulate you guys for the awesome tool... I came here only to see what this thing was up to and I have to tell that I'm very impressed with what this tool can do. French guys are making a revolution on Joomla... first with Seblod and now Cook...
Griiettner (forum)

Get Started