Closed chonz0 closed 7 years ago
Do you get any database queries from the call to versions
?
Thanks for replying :-)
Yes, according to DebugKit, when I call
$versions = $page->versions();
I get the following queries in SQL log:
SHOW FULL COLUMNS FROM `version` 7 8
SHOW INDEXES FROM `version` 1 1
SELECT * FROM information_schema.key_column_usage AS kcu INNER JOIN information_schema.referential_constraints AS rc ON ( kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME AND kcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA ) WHERE kcu.TABLE_SCHEMA = 'cakephp3cms' AND kcu.TABLE_NAME = 'version' AND rc.TABLE_NAME = 'version' 0 16
SHOW TABLE STATUS WHERE Name = 'version' 1 1
SELECT version.id AS `version__id`, version.version_id AS `version__version_id`, version.model AS `version__model`, version.foreign_key AS `version__foreign_key`, version.field AS `version__field`, version.content AS `version__content`, version.created AS `version__created` FROM version version INNER JOIN (SELECT (Pages.id) FROM pages Pages GROUP BY Pages.id ) Pages ON version.foreign_key = (Pages.id) WHERE (version.model = 'Pages' AND version.foreign_key in (21) AND field in ('id','title','content','image','slug','album_id','version_id','created')) 24 1
The last query returns 24 rows (these are all the records I currently have in my ´version´table)
BTW: I'm from Argentina, so my main language is spanish, but I wanted to write in english just in case someone else could help too
Can you create a sample app for me (including data in your database) so I can test this out?
Ok, so I created a brand new clean Cake3 app, set up everything to work with my custom plugin, then installed your awesome CakePHP Version plugin and... voila! I have no idea what was wrong with my setup... I'll do a little more research on it, but so far I have no clue :S If it happens to be something with the plugin I'll let you know, but it looks like it was something else. Thank you -again- very much for your time and your great work! Cheers! Gonzalo
I looks like the version plugin is having trouble with the my 'pages' model. I tried a new one, 'sections', and everything keeps working great (as in my 'posts' model).
Sorry... Reopening this...
I made a fresh install of CakePHP, baked MVC for a couple tables (posts & sections), to be sure it wasn't an issue with the 'pages' naming... But the version plugin keeps acting weird... I've observed that: 1) In 'version' table, the 'version_id' field keeps incrementing as an auto-increment field, it does not keep track of version per foreign_key 2) Besides that, all data seems to be saved OK, the issue comes when I have to read the versions using $model->versions(); The first entry is read correctly, but the second does not.
I've uploaded the app to a GitHub repo: https://github.com/chonz0/cakephp-version-app Inside the 'mysql_dump' folder, there is an exact copy of my database for you to import it and see if you face the same issue.
Thanks in advance, Gonzalo
Ok, I think I got something...
In VersionTrait.php, inside the versions() method, I replaced:
$conditions = ['primaryKey' => $this->id];
with:
$conditions = [ 'conditions' => ['id' => $this->id] ];
and now I do get all versions of each entry as desired (maybe, instead of 'id' => $this->id we should use something generic, like $model.'.'.$primaryKey, but I don't know how to do that.
This looks like resolved in current master?
Hi,
First of all, thanks a lot for your awesome work :-) I'm trying to implement your awesome plugin, but I'm having some troubles with it, and I think it may be a bug...
The records (versions) do get saved correctly to the database, but whenever I try to show it in my view, I get nothing... :-(
Am I missing something?
Thanks in advance! Gonzalo
src/Model/Entity/Page.php
src/Model/Table/PagesTable.php
src/Controller/PagesController.php