Part of the EllisLab Network
   
20 of 20
20
[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition)
Posted: 06 December 2009 04:21 PM   [ Ignore ]   [ # 191 ]  
Grad Student
Avatar
Rank
Total Posts:  97
Joined  08-29-2007

Hi,

Im still using 1.5.4 that’s why I ask my question here:

I have a controller where I instantiate my DataMapper model:

/* Bike-Object */
        
$b = new Bike();
        
$b->where('key'$key);
        
$b->where('color''red');
        
$b->get(); 

The model looks like this:

class Bike extends DataMapper {

    
var $table 'cti_bikes';

    public function 
Bike () {
      parent
::DataMapper();
    
}

When I run

$b->count(); 

it return 2 even there is only 1 database entry.

When I run

$b->check_last_query(); 

the database query is shown twice.

It seems I am doing something basically wrong as it seems to affect all my datamapper models. The Constructor is always called twice.

Any idea what could be wrong?

Thanks for help.

 Signature 

Visit the german-speaking CI-community at http://codeigniter.ch
FreeBSD- and Server-Tutorials at http://serverzeit.de
The event-calendar for Mini-Drivers at http://miniyourlife.com

Profile
 
 
Posted: 06 December 2009 05:52 PM   [ Ignore ]   [ # 192 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

If you want the number of items returned from a query, just use the PHP methods:

count($b->all

Calling get clears the current query.  count attempts to run another query, but because you are calling without any where statements, it simply returns the number of rows in the table.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 06 December 2009 05:55 PM   [ Ignore ]   [ # 193 ]  
Grad Student
Avatar
Rank
Total Posts:  97
Joined  08-29-2007

Thanks for your reply, makes sense.

But why is it called twice? This seems to another mistake I am making.

Any idea what could be wrong here?

Thanks for your help!

Another thing is when I run the query above, if I run $b->exists() after get() it says FALSE. I thought it should work like that? Or does it only work after a “get_by_id”?

 Signature 

Visit the german-speaking CI-community at http://codeigniter.ch
FreeBSD- and Server-Tutorials at http://serverzeit.de
The event-calendar for Mini-Drivers at http://miniyourlife.com

Profile
 
 
Posted: 07 December 2009 02:32 AM   [ Ignore ]   [ # 194 ]  
Grad Student
Avatar
Rank
Total Posts:  97
Joined  08-29-2007

Just by new Bike; it already runs twice SELECT * FROM `cti_bikes` LIMIT 1

Is that supposed to be like that?

 Signature 

Visit the german-speaking CI-community at http://codeigniter.ch
FreeBSD- and Server-Tutorials at http://serverzeit.de
The event-calendar for Mini-Drivers at http://miniyourlife.com

Profile
 
 
Posted: 07 December 2009 02:36 AM   [ Ignore ]   [ # 195 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

That’s not a COUNT query.  It doesn’t have COUNT in it.

See here for more information about that query.  (The Google search on the docs turns it up, just so you know.  I know it isn’t in the FAQs, however.)

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 07 December 2009 02:52 AM   [ Ignore ]   [ # 196 ]  
Grad Student
Avatar
Rank
Total Posts:  97
Joined  08-29-2007

Ok, that solved the “Limit 1” messages, thanks. I didnt find this as I was not thinking about production cache yet. Thanks.

So it seems I have a general problem about querries. Now it shows me the session-querries (not related to DMZ) to be run twice.

I need to check if “check_last_query” might be buggy or what is going wrong in general.

 Signature 

Visit the german-speaking CI-community at http://codeigniter.ch
FreeBSD- and Server-Tutorials at http://serverzeit.de
The event-calendar for Mini-Drivers at http://miniyourlife.com

Profile
 
 
Posted: 07 December 2009 02:57 AM   [ Ignore ]   [ # 197 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

check_last_query auto outputs to the browser (and still returns the result).  Maybe that’s your problem?  Check the docs for check_last_query.  It is not buggy.

Also, if you are debugging, I highly recommend using $this->output->enable_profiler(TRUE); whenever possible.  It provides more detail.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 07 December 2009 02:59 AM   [ Ignore ]   [ # 198 ]  
Grad Student
Avatar
Rank
Total Posts:  97
Joined  08-29-2007

Argh, Im hunting ghosts.

Thanks for pointing me to this. Seems it was just too late last night.

Thanks and sorry for being blind.

 Signature 

Visit the german-speaking CI-community at http://codeigniter.ch
FreeBSD- and Server-Tutorials at http://serverzeit.de
The event-calendar for Mini-Drivers at http://miniyourlife.com

Profile
 
 
Posted: 08 March 2010 04:08 PM   [ Ignore ]   [ # 199 ]  
Grad Student
Avatar
Rank
Total Posts:  44
Joined  09-21-2008

Hey, is there a way to write a trigger? (I think it’s called a trigger.) I want to put a method in a model that gets called when an object of that type gets deleted. It’s an “Image” model, and if an Image object gets deleted, I want the model to delete all the appropriate image files.

Greg

Profile
 
 
   
20 of 20
20