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

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

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.086 seconds
  I still don't believe he can really be human to do all this ! From all of the forums that I've ever participated in this is certainly the one that most encapsulates the feeling of being truly open source where everyone's opinions and contributions can and will shape the development of the service! It's truly awesome! Hope you enjoy cooking and look forward to reading and contributing to any of the editorial work that you proposed too!! Thanks
Gez (audibleid - JED)

Get Started