Skip to content

Commit

Permalink
fix simply versioned association for rails 3
Browse files Browse the repository at this point in the history
Change-Id: I9545f224ef8340f3efeda04682999ace811c2352
Reviewed-on: https://gerrit.instructure.com/28535
Tested-by: Jenkins <[email protected]>
Reviewed-by: Cody Cutrer <[email protected]>
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
maneframe authored and ccutrer committed Jan 16, 2014
1 parent 087dee0 commit 5ff6df6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions vendor/plugins/simply_versioned/lib/simply_versioned.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def simply_versioned( options = {} )

has_many :versions, :order => 'number DESC', :as => :versionable,
:dependent => :destroy,
:inverse_of => :versionable,
:extend => VersionsProxyMethods
:inverse_of => :versionable, :extend => VersionsProxyMethods
# INSTRUCTURE: Added to allow quick access to the most recent version
# See 'current_version' below for the common use of current_version_unidirectional
has_one :current_version_unidirectional, :class_name => 'Version', :order => 'number DESC', :as => :versionable, :dependent => :destroy, :extend => VersionsProxyMethods
Expand Down Expand Up @@ -251,7 +250,9 @@ def populate_versionables(versions)
end

def populate_versionable(version)
version.versionable = proxy_owner if version && !version.frozen?
if version && !version.frozen?
version.versionable = CANVAS_RAILS2 ? proxy_owner : proxy_association.owner
end
version
end

Expand All @@ -263,13 +264,13 @@ def get_version( number )

# Get the first Version corresponding to this model.
def first_version
populate_versionable reorder( 'number ASC' ).first
populate_versionable reorder( 'number ASC' ).limit(1).to_a.first
end
alias_method :first, :first_version

# Get the current Version corresponding to this model.
def current_version
populate_versionable reorder( 'number DESC' ).first
populate_versionable reorder( 'number DESC' ).limit(1).to_a.first
end
alias_method :current, :current_version

Expand All @@ -283,13 +284,13 @@ def clean_old_versions( versions_to_keep )

# Return the Version for this model with the next higher version
def next_version( number )
populate_versionable reorder( 'number ASC' ).where( "number > ?", number ).first
populate_versionable reorder( 'number ASC' ).where( "number > ?", number ).limit(1).to_a.first
end
alias_method :next, :next_version

# Return the Version for this model with the next lower version
def previous_version( number )
populate_versionable reorder( 'number DESC' ).where( "number < ?", number ).first
populate_versionable reorder( 'number DESC' ).where( "number < ?", number ).limit(1).to_a.first
end
alias_method :previous, :previous_version
end
Expand Down

0 comments on commit 5ff6df6

Please sign in to comment.