I''m having some problems getting acts_as_versioned working - can anyone see if I''m making a really stupid mistake here? Here''s my schema: CREATE TABLE `cache_versions` ( `id` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `cache_title` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, `browser_content_type` varchar(255) NOT NULL, `cache` text NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`version`) ); CREATE TABLE `caches` ( `id` int(11) NOT NULL auto_increment, `version` int(11) NOT NULL, `cache_title` varchar(100) NOT NULL, `url` varchar(255) NOT NULL default '''', `cache` text NOT NULL, `browser_content_type` varchar(255) NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ); I''ve added the acts_as_versioned to my model file: class Cache < ActiveRecord::Base acts_as_versioned validates_presence_of :cache_title, :url, :cache validates_uniqueness_of :url end When I update the record it never updates the cache_versions table at all - it just updates the caches table like it used to. I''ve scoured Google and just can''t find the answer to this problem - it doesn''t seem to see the acts_as_versioned at all. Am I missing something simple? I assumed that when I did cache.save in my application that it''d automatically update the versions table. If somebody could point me to some additional code somewhere - I''d be very appreciative - I''ve already gone through the wiki and rdoc documentation but I appear to have missed something. I''m running this on 10.4.2 (OS X) using webrick and MySQL 5.0.13. Be gentle - this is my first Rails application and it''s pretty much complete - I just wanted to keep a few versions around whenever my cache db updates. Thanks for any help anyone can offer.
I just restarted my rails app and now it''s failing like it probably should: http://meemo.nonfiction.ca/~darron/error.html Any ideas? On 10/27/05, Darron Froese <dfroese-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m having some problems getting acts_as_versioned working - can > anyone see if I''m making a really stupid mistake here? > > Here''s my schema: > > CREATE TABLE `cache_versions` ( > `id` int(11) NOT NULL, > `cache_id` int(11) NOT NULL, > `cache_title` varchar(255) NOT NULL, > `url` varchar(255) NOT NULL, > `browser_content_type` varchar(255) NOT NULL, > `cache` text NOT NULL, > `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', > `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', > PRIMARY KEY (`version`) > ); > > > CREATE TABLE `caches` ( > `id` int(11) NOT NULL auto_increment, > `version` int(11) NOT NULL, > `cache_title` varchar(100) NOT NULL, > `url` varchar(255) NOT NULL default '''', > `cache` text NOT NULL, > `browser_content_type` varchar(255) NOT NULL, > `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', > `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', > PRIMARY KEY (`id`) > ); > > I''ve added the acts_as_versioned to my model file: > > class Cache < ActiveRecord::Base > acts_as_versioned > validates_presence_of :cache_title, :url, :cache > validates_uniqueness_of :url > end > > When I update the record it never updates the cache_versions table at > all - it just updates the caches table like it used to. I''ve scoured > Google and just can''t find the answer to this problem - it doesn''t > seem to see the acts_as_versioned at all. > > Am I missing something simple? I assumed that when I did cache.save in > my application that it''d automatically update the versions table. > > If somebody could point me to some additional code somewhere - I''d be > very appreciative - I''ve already gone through the wiki and rdoc > documentation but I appear to have missed something. > > I''m running this on 10.4.2 (OS X) using webrick and MySQL 5.0.13. > > Be gentle - this is my first Rails application and it''s pretty much > complete - I just wanted to keep a few versions around whenever my > cache db updates. > > Thanks for any help anyone can offer. >
Hi, Darron, are you getting your cache_versions table created with this ddl? Or is the PRIMARY KEY (version) just a typo. I''m getting the following error: dbedit.core.DataException: Couldn''t execute query:CREATE TABLE `cache_versions` ( `id` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `cache_title` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, `browser_content_type` varchar(255) NOT NULL, `cache` text NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`version`) ) java.sql.SQLException: Key column ''version'' doesn''t exist in table regards Jan Prill Darron Froese wrote: I''m having some problems getting acts_as_versioned working - can anyone see if I''m making a really stupid mistake here? Here''s my schema: CREATE TABLE `cache_versions` ( `id` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `cache_title` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, `browser_content_type` varchar(255) NOT NULL, `cache` text NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`version`) ); CREATE TABLE `caches` ( `id` int(11) NOT NULL auto_increment, `version` int(11) NOT NULL, `cache_title` varchar(100) NOT NULL, `url` varchar(255) NOT NULL default '''', `cache` text NOT NULL, `browser_content_type` varchar(255) NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ); I''ve added the acts_as_versioned to my model file: class Cache < ActiveRecord::Base acts_as_versioned validates_presence_of :cache_title, :url, :cache validates_uniqueness_of :url end When I update the record it never updates the cache_versions table at all - it just updates the caches table like it used to. I''ve scoured Google and just can''t find the answer to this problem - it doesn''t seem to see the acts_as_versioned at all. Am I missing something simple? I assumed that when I did cache.save in my application that it''d automatically update the versions table. If somebody could point me to some additional code somewhere - I''d be very appreciative - I''ve already gone through the wiki and rdoc documentation but I appear to have missed something. I''m running this on 10.4.2 (OS X) using webrick and MySQL 5.0.13. Be gentle - this is my first Rails application and it''s pretty much complete - I just wanted to keep a few versions around whenever my cache db updates. Thanks for any help anyone can offer. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 10/27/05, Darron Froese <dfroese-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m having some problems getting acts_as_versioned working - can > anyone see if I''m making a really stupid mistake here?This is me on the latest version of rails: $ rails foo $ cd foo # set up database.yml $ rake db_schema_dump $ script/generate model cache # Initial schema: create_table "cache_versions", :force => true do |t| t.column "cache_id", :integer t.column "version", :integer t.column "cache_title", :string t.column "url", :string t.column "browser_content_type", :string t.column "data", :text # using a ''cache'' column gave me a AssociationTypeMismatch... WTF? t.column "created_on", :datetime t.column "updated_on", :datetime end $ rake db_schema_import # Uncomment this in environment.rb: # config.active_record.schema_format = :ruby $ script/generate migration add_versioned # migration: def self.up Cache.create_versioned_table end $ script/console>> c=Cache.create=> #<Cache:0x240a9c4 @new_record=false, @new_record_before_save=true, @attributes={"created_on"=>Thu Oct 27 13:51:35 CDT 2005, "updated_on"=>Thu Oct 27 13:51:35 CDT 2005, "url"=>nil, "id"=>2, "browser_content_type"=>nil, "version"=>1, "cache_id"=>nil, "cache_title"=>nil, "data"=>nil}, @changed_attributes=[], @errors=#<ActiveRecord::Errors:0x2759b98 @base=#<Cache:0x240a9c4 ...>, @errors={}>>>> c.versions=> [#<ActiveRecord::Acts::Versioned::CacheVersion:0x2726a90 @attributes={"created_on"=>"2005-10-27 13:51:35", "updated_on"=>"2005-10-27 13:51:35", "url"=>nil, "id"=>"1", "browser_content_type"=>nil, "cache_id"=>"2", "version"=>"1", "cache_title"=>nil, "data"=>nil}>]>> Cache.versioned_class.count=> 1 Works for me. Here''s the schema it generated for me: create_table "cache_versions", :force => true do |t| t.column "cache_id", :integer t.column "version", :integer t.column "cache_title", :string t.column "url", :string t.column "browser_content_type", :string t.column "data", :text t.column "created_on", :datetime t.column "updated_on", :datetime end create_table "caches", :force => true do |t| t.column "cache_id", :integer t.column "cache_title", :string t.column "url", :string t.column "browser_content_type", :string t.column "data", :text t.column "created_on", :datetime t.column "updated_on", :datetime t.column "version", :integer end Now that I''ve done all this, I noticed you''re missing a version field in the actual model. Use Foo.create_versioned_table to set up the versioned table. This checks for and adds any missing necessary fields. Question: Should it throw an error? Or perhaps a log message when it can''t/won''t save a version? -- rick http://techno-weenie.net
On 10/27/05, Darron Froese <dfroese-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I just restarted my rails app and now it''s failing like it probably should: > > http://meemo.nonfiction.ca/~darron/error.html > > Any ideas?That''s the error I got. Now that I think about it, the versioned model has a belongs_to association created that points back to the original model. @user_version.user would get you the current @user model. I''d rename your model for now. If it''s a huge deal I may just add some more configuration options for that so you can change it. -- rick http://techno-weenie.net
> I''d rename your model for now. If it''s a huge deal I may just add > some more configuration options for that so you can change it.Eh, I mean rename your model attribute. Instead of ''cache'', call it ''data'' or something. @cache.data = ''foo'' -- rick http://techno-weenie.net
On 10/27/05, Jan Prill <JanPrill-sTn/vYlS8ieELgA04lAiVw@public.gmane.org> wrote:> Hi, Darron, > > are you getting your cache_versions table created with this ddl? Or is the > PRIMARY KEY (version) just a typo. I''m getting the following error:I noticed that and changed ''id'' to to ''version'' - thought it was OK when I wasn''t getting an error.
Sweet - I''m really close now. The only problem I''m having now is that one column isn''t being saved into the versions table - everything else is. I thought it might be a naming problem (like cache.cache before) and so I named it ''data_foo'' (and tried ''data'' before) - it''s updating in the caches table - but not in the versions table. Here''s my ''almost working'' schema: CREATE TABLE `cache_versions` ( `id` int(11) NOT NULL auto_increment, `version` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `cache_title` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, `browser_content_type` varchar(255) NOT NULL, `data_foo` text NOT NULL, `created_on` datetime NOT NULL, `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ); CREATE TABLE `caches` ( `id` int(11) NOT NULL auto_increment, `version` int(11) NOT NULL, `cache_title` varchar(100) NOT NULL, `url` varchar(255) NOT NULL default '''', `data_foo` text NOT NULL, `browser_content_type` varchar(255) NOT NULL, `created_on` datetime NOT NULL default ''0000-00-00 00:00:00'', `updated_on` datetime NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ); Now when I update a record this is what happens in the development.log: User Columns (0.004511) SHOW FIELDS FROM users Processing UpdateController#single (for 127.0.0.1 at Thu Oct 27 14:46:59 MDT 2005) Parameters: {"action"=>"single", "id"=>"2", "controller"=>"update"} Cache Load (0.004909) SELECT * FROM caches WHERE caches.id = ''2'' LIMIT 1 Cache Columns (0.004267) SHOW FIELDS FROM caches SQL (0.000290) BEGIN Cache Load (0.001249) SELECT * FROM caches WHERE url ''http://content.investmentplanet.com/xml/single/freehold/stockquote.asp'' AND id <> 2 LIMIT 1 SQL (0.001049) SELECT MAX(version)+1 AS next_version FROM cache_versions WHERE cache_id = 2 Cache Update (0.001051) UPDATE caches SET `version` = 3, `browser_content_type` = ''text/xml'', `data_foo` = ''<?xml version=\"1.0\"?>\r\n<StockQuote><CDN><field name=\"Symbol\"><value>FRU.U</value> ... Snip lots of XML ...\r\n'', `updated_on` = ''2005-10-27 14:46:59'', `cache_title` = ''Freehold Stockquote'', `url` ''http://content.investmentplanet.com/xml/single/freehold/stockquote.asp'', `created_on` = ''2005-10-17 19:44:00'' WHERE id = 2 ActiveRecord::Acts::Versioned::CacheVersion Columns (0.004987) SHOW FIELDS FROM cache_versions SQL (0.001143) INSERT INTO cache_versions (`created_on`, `updated_on`, `url`, `browser_content_type`, `cache_id`, `version`, `cache_title`) VALUES(''2005-10-17 19:44:00'', ''2005-10-27 14:46:59'', ''http://content.investmentplanet.com/xml/single/freehold/stockquote.asp'', ''text/xml'', 2, 3, ''Freehold Stockquote'') SQL (0.000270) COMMIT Redirected to http://localhost:3000/admin/list Completed in 0.28628 (3 reqs/sec) | DB: 0.02373 (8%) [http://localhost/update/single/2] User Columns (0.003583) SHOW FIELDS FROM users Processing AdminController#list (for 127.0.0.1 at Thu Oct 27 14:46:59 MDT 2005) Parameters: {"action"=>"list", "controller"=>"admin"} Cache Count (0.002679) SELECT COUNT(*) FROM caches Cache Load (0.001096) SELECT * FROM caches LIMIT 10 Rendering within layouts/admin Rendering admin/list (200 OK) Cache Columns (0.007140) SHOW FIELDS FROM caches Completed in 0.10755 (9 reqs/sec) | Rendering: 0.08270 (76%) | DB: 0.00736 (6%) [http://localhost/admin/list] Thanks again - any idea?
On 10/27/05, Darron Froese <dfroese-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sweet - I''m really close now. > > The only problem I''m having now is that one column isn''t being saved > into the versions table - everything else is. I thought it might be a > naming problem (like cache.cache before) and so I named it ''data_foo'' > (and tried ''data'' before) - it''s updating in the caches table - but > not in the versions table.No clue. It''s not doing any magic for this part. It loops through all the versioned attributes and sets them in the new object. These are the only ones that are skipping: [self.primary_key, inheritance_column, ''version'', ''lock_version'', versioned_inheritance_column] Try doing Cache.non_versioned_fields and see what pops out. The actual method that does the saving is clone_versioned_model: http://ar-versioned.rubyforge.org/classes/ActiveRecord/Acts/Versioned/ActMethods.html#M000012 -- rick http://techno-weenie.net