forked from paper-trail-gem/paper_trail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lyfeyaj/has-many-associations
add has many associations functionality
- Loading branch information
Showing
9 changed files
with
217 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ Gemfile.lock | |
vendor/* | ||
.idea | ||
.rvmrc | ||
.tags | ||
.tags_sorted_by_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lib/generators/paper_trail/templates/add_transaction_id_column_to_versions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddTransactionIdColumnToVersions < ActiveRecord::Migration | ||
def self.up | ||
add_column :versions, :transaction_id, :integer | ||
add_index :versions, [:transaction_id] | ||
end | ||
|
||
def self.down | ||
remove_column :versions, :transaction_id | ||
remove_index :versions, [:transaction_id] | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
lib/generators/paper_trail/templates/create_version_associations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateVersionAssociations < ActiveRecord::Migration | ||
def self.up | ||
create_table :version_associations do |t| | ||
t.integer :version_id | ||
t.string :foreign_key_name, :null => false | ||
t.integer :foreign_key_id | ||
end | ||
add_index :version_associations, [:version_id] | ||
add_index :version_associations, [:foreign_key_name, :foreign_key_id], :name => 'index_on_foreign_key_name_and foreign_key_id' | ||
end | ||
|
||
def self.down | ||
remove_index :version_associations, [:version_id] | ||
remove_index :version_associations, [:foreign_key_name, :foreign_key_id], :name => 'index_on_foreign_key_name_and foreign_key_id' | ||
drop_table :version_associations | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module PaperTrail | ||
class VersionAssociation < ActiveRecord::Base | ||
belongs_to :version | ||
|
||
attr_accessible :version_id, :foreign_key_name, :foreign_key_id if PaperTrail.active_record_protected_attributes? | ||
end | ||
end |
Oops, something went wrong.