Updating models to contain table name (prevents ambiguous queries)

This commit is contained in:
Daniel Munn 2012-06-29 09:11:04 +01:00
parent b8716a5cc2
commit a8cf03a958
3 changed files with 10 additions and 10 deletions

View File

@ -32,10 +32,10 @@ class DmsfFile < ActiveRecord::Base
belongs_to :project
belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id"
has_many :revisions, :class_name => "DmsfFileRevision", :foreign_key => "dmsf_file_id",
:order => "major_version DESC, minor_version DESC, updated_at DESC",
:order => "#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC",
:dependent => :destroy
has_many :locks, :class_name => "DmsfLock", :foreign_key => "entity_id",
:order => "updated_at DESC",
:order => "#{DmsfLock.table_name}.updated_at DESC",
:conditions => {:entity_type => 0},
:dependent => :destroy
belongs_to :deleted_by_user, :class_name => "User", :foreign_key => "deleted_by_user_id"
@ -82,7 +82,7 @@ class DmsfFile < ActiveRecord::Base
def self.project_root_files(project)
visible.find(:all, :conditions =>
["dmsf_folder_id is NULL and project_id = :project_id",
{:project_id => project.id}], :order => "name ASC")
{:project_id => project.id}], :order => "#{self.table_name}.name ASC")
end
def self.find_file_by_name(project, folder, name)

View File

@ -26,14 +26,14 @@ class DmsfFolder < ActiveRecord::Base
belongs_to :project
belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id"
has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "title ASC",
has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "#{DmsfFolder.table_name}.title ASC",
:dependent => :destroy
has_many :files, :class_name => "DmsfFile", :foreign_key => "dmsf_folder_id",
:dependent => :destroy
belongs_to :user
has_many :locks, :class_name => "DmsfLock", :foreign_key => "entity_id",
:order => "updated_at DESC",
:order => "#{DmsfLock.table_name}.updated_at DESC",
:conditions => {:entity_type => 1},
:dependent => :destroy
@ -61,7 +61,7 @@ class DmsfFolder < ActiveRecord::Base
folders.each do |folder|
if folder == self.folder
errors.add(:folder, l(:error_create_cycle_in_folder_dependency))
return false
return false
end
folder.subfolders.each {|f| folders.push(f)}
end
@ -70,17 +70,17 @@ class DmsfFolder < ActiveRecord::Base
def self.project_root_folders(project)
find(:all, :conditions =>
["dmsf_folder_id is NULL and project_id = :project_id", {:project_id => project.id}], :order => "title ASC")
["#{DmsfFolder.table_name}.dmsf_folder_id is NULL and #{DmsfFolder.table_name}.project_id = :project_id", {:project_id => project.id}], :order => "#{DmsfFolder.table_name}.title ASC")
end
def self.find_by_title(project, folder, title)
if folder.nil?
visible.find(:first, :conditions =>
["dmsf_folder_id is NULL and project_id = :project_id and title = :title",
["#{DmsfFolder.table_name}.dmsf_folder_id is NULL and #{DmsfFolder.table_name}.project_id = :project_id and #{DmsfFolder.table_name}.title = :title",
{:project_id => project.id, :title => title}])
else
visible.find(:first, :conditions =>
["dmsf_folder_id = :folder_id and title = :title",
["#{DmsfFolder.table_name}.dmsf_folder_id = :folder_id and #{DmsfFolder.table_name}.title = :title",
{:project_id => project.id, :folder_id => folder.id, :title => title}])
end
end

View File

@ -51,7 +51,7 @@ class DmsfLock < ActiveRecord::Base
end
def self.delete_expired
self.delete_all ['expires_at IS NOT NULL && expires_at < ?', Time.now]
self.delete_all ["#{DmsfLock.table_name}.expires_at IS NOT NULL && #{DmsfLock.table_name}.expires_at < ?", Time.now]
end
#Lets allow our UUID to be searchable