I have a model that tracks views. It's a very basic model as you can see below. There are currently only 2 methods. One queries the database, and one to add to the views table.
The function that checks the table returns either a view object, or null. It's a static method called inside of the save_view method. If the save_view method returns null, a new view is built, but if it returns an object, the view property is pulled, and a 1 is added to it, then saved to the database.
Here is where it gets weird.
The new build works fine. It just initializes and saves a row with 1 view. If I use the view object that's already been initialized, and add 1 to the view, it is saving as 2. I have no idea what is going on.
If I interrupt the flow with Debug::dump($view);
it saves by 1 as expected.
So, for example, if the row currently has 3 views, and I do $view->set('views', ($view->views + 1));
, you would think that it would save as views = 4, but it's skipping ahead to views = 5. When interrupted it saves as views = 4.
I've tried this a whole variety of ways, nothing seems to be working. I can get them all to save, but I'm still getting the same unexpected results. Am I missing something basic here, is it possible the code is flowing too fast, or have I discovered a bug? Never seen anything like this before. Thanks for taking a look.
I was having a really hard time trying to post this here. I tried a couple times and ended up taking it over to stack overflow.
The code in question: http://stackoverflow.com/q/30541286/758554
Okay, it's back, and i'm going completely mad. I have grepped my entire project, and I cannot find where this is coming from! For some reason, the call to Model::find is happening twice, or the call to the controller action I am not quite sure. If I use Debug::backtrace() or Debug::dump() I don't have an issue.I originally thought it might be a relational call, so I've ripped out all of my class and it's still occurring.
Here is the stripped down version of my controller action:
public function action_view($id = null) {
$this->template->content = View::forge($view, $data);
}
with debug commented out in my log, i get 2 calls, the first is a serialized array, the second is just N.
INFO - 2015-05-30 17:59:27 --> Joke: N;
My MySQL database is getting hit twice as well. And this is even more confusing. For some unbeknownst reason, There is a query being called for 'favicon'. I have absolutely no idea why this is occurring. As you can see, the first call grabs the joke and is perfect, the second call is looking for a joke with an id of 'favicon'?
150530 17:59:26 951 Connect dmotivat_casper@localhost on dmotivat_dmotivated
951 Query SET NAMES 'utf8'
951 Query SELECT `t0`.`id` AS `t0_c0`, `t0`.`user_id` AS `t0_c1`, `t0`.`title` AS `t0_c2`, `t0`.`body` AS `t0_c3`, `t0`.`url_id` AS `t0_c4`, `t0`.`ip` AS `t0_c5`, `t0`.`created_at` AS `t0_c6`, `t0`.`updated_at` AS `t0_c7`, `t0`.`active` AS `t0_c8` FROM `jokes` AS `t0` WHERE `t0`.`id` = '14' LIMIT 1
951 Query SELECT * FROM `users` WHERE `username` = 'casper'
951 Quit
150530 17:59:27 952 Connect dmotivat_casper@localhost on dmotivat_dmotivated
952 Query SET NAMES 'utf8'
952 Query SELECT `t0`.`id` AS `t0_c0`, `t0`.`user_id` AS `t0_c1`, `t0`.`title` AS `t0_c2`, `t0`.`body` AS `t0_c3`, `t0`.`url_id` AS `t0_c4`, `t0`.`ip` AS `t0_c5`, `t0`.`created_at` AS `t0_c6`, `t0`.`updated_at` AS `t0_c7`, `t0`.`active` AS `t0_c8` FROM `jokes` AS `t0` WHERE `t0`.`id` = 'favicon' LIMIT 1
I have grepped my whole project, and cannot find where this call is coming from, or why it's happening.
If i use the Debug methods, only 1 call to the DB occurs. I believe the only reason I even discovered this situation is because of the counter I put in.
I don't know if it matters or not, i'm using version 1.7
I would deeply appreciate any thoughts, I'm going mad! Also, I tried to adjust the format, sorry.
It looks like you're new here. If you want to get involved, click one of these buttons!