Created
November 30, 2012 01:58
-
-
Save aaronvb/4173290 to your computer and use it in GitHub Desktop.
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
class Checkpoint < ActiveRecord::Base | |
has_many :note_joins, as: :notable | |
has_many :notes, through: :note_joins | |
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
class CreateNoteJoins < ActiveRecord::Migration | |
def change | |
create_table :note_joins do |t| | |
t.integer :note_id | |
t.integer :notable_id | |
t.string :notable_type | |
t.timestamps | |
end | |
add_index :note_joins, [:notable_id, :notable_type] | |
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
class CreateNotes < ActiveRecord::Migration | |
def change | |
create_table :notes do |t| | |
t.text :content | |
t.integer :user_id | |
t.timestamps | |
end | |
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
class Location < ActiveRecord::Base | |
has_many :note_joins, as: :notable | |
has_many :notes, through: :note_joins | |
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
class Note < ActiveRecord::Base | |
attr_accessible :content, :user_id | |
belongs_to :notable, polymorphic: true | |
belongs_to :user | |
has_many :note_joins | |
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
class NoteJoin < ActiveRecord::Base | |
belongs_to :notable, polymorphic: true | |
belongs_to :note | |
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
class Note < ActiveRecord::Base | |
attr_accessible :content, :user_id | |
belongs_to :notable, polymorphic: true | |
belongs_to :user | |
has_many :note_joins | |
has_many :locations, through: :note_joins, source: :notable, source_type: 'Location' | |
has_many :checkpoints, through: :note_joins, source: :notable, source_type: 'Checkpoint' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment