Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version_at throws an error #288

Closed
JacobEvelyn opened this issue Oct 16, 2013 · 10 comments
Closed

version_at throws an error #288

JacobEvelyn opened this issue Oct 16, 2013 · 10 comments
Assignees
Milestone

Comments

@JacobEvelyn
Copy link
Contributor

I'm using a separate version class for each of my versioned models, and when I call object.version_at(timestamp) I unfortunately get:

PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """"
LINE 1: SELECT  "".* FROM ""  WHERE (created_at > '2013-09-08 16:56:...

Looks like the versions table and columns aren't getting found properly. Is this a known issue?

@batter
Copy link
Collaborator

batter commented Oct 16, 2013

Which version of PaperTrail are you using? Also, please make sure you have read and followed directions in the README about how to use custom version classes.

@JacobEvelyn
Copy link
Contributor Author

Thanks for the quick response. I'm using PaperTrail 3.0.0.beta1, and I've followed the directions on the README. Additionally, it seems the self.table_name = ... line that the README says to put into versions classes may be unnecessary (the rest of PaperTrail works without it for me).

@batter
Copy link
Collaborator

batter commented Oct 16, 2013

So you've definitely passed in the :class_name option into your has_paper_trail declarations on each model?

@JacobEvelyn
Copy link
Contributor Author

Yep.

@batter
Copy link
Collaborator

batter commented Oct 16, 2013

Please try running this in your console. Say you have a model named Widget that declares has_paper_trail.

> Widget.version_class_name
=> "PaperTrail::Version" # this is the default value, wondering what yours returns
> Widget.versions_association_name
=> :versions # again, this is the default value, wondering what yours returns

In fact it would be helpful if you could provide a gist or a copy of the code for one of the models and it's counterpart custom version class. I'm having difficulty helping to debug with the limited information you've provided. Thanks.

@JacobEvelyn
Copy link
Contributor Author

Sure thing. Here are the relevant parts of my model:

module SIS
  class CourseSection < ActiveRecord::Base

    # Set up PaperTrail versioning.
    has_paper_trail class_name: "SIS::CourseSectionVersion",
                    meta: { :import_create => :import_create } # This is used when importing data.
    attr_accessor :import_create
  end

  class CourseSectionVersion < PaperTrail::Version
    # self.table_name is unnecessary here
    self.sequence_name = :course_section_version_id_sequence
  end
end

And I also have sis.rb:

module SIS
  def self.table_name_prefix
    'sis_'
  end
end

My tables are named sis_course_sections and sis_course_section_versions.

And, in the console, I have:

> SIS::CourseSection.version_class_name
=> "SIS::CourseSectionVersion" 
> SIS::CourseSection.versions_association_name
=> :versions 

Thanks for all the help.

@batter
Copy link
Collaborator

batter commented Oct 16, 2013

And you also added an initializer like so (as the README states is necessary for custom version classes)?

# config/initializers/paper_trail.rb
PaperTrail::Version.module_eval do
  self.abstract_class = true
end

@JacobEvelyn
Copy link
Contributor Author

Yes, I have that initializer as well.

@ghost ghost assigned batter Oct 17, 2013
@batter batter closed this as completed in eb01ca3 Oct 17, 2013
@batter
Copy link
Collaborator

batter commented Oct 17, 2013

@JacobEvelyn - Think I figured out the issue and fixed it with eb01ca3. Please try using the head of the master branch from GitHub and see if that fixes the issue. Add this to your Gemfile:

gem 'paper_trail', :github => 'airblade/paper_trail'

@JacobEvelyn
Copy link
Contributor Author

Ah, beautiful! Works perfectly. Thanks for the help and the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants