added ability to create synapses between nodes of same type

This commit is contained in:
Connor Turland 2012-10-05 16:40:30 -04:00
parent a7d89bf798
commit ca2898fe3d
8 changed files with 77 additions and 5 deletions

View file

@ -4,6 +4,15 @@ belongs_to :user
has_many :groupgroup_c, :foreign_key => 'parent_group_id', :class_name => 'Groupgroup'
has_many :groupgroup_p, :foreign_key => 'group_id', :class_name => 'Groupgroup'
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Group'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Group'}
has_many :groups1, :through => :synapses2, :source => :group1
has_many :groups2, :through => :synapses1, :source => :group2
def siblings
groups1 + groups2
end
has_many :grouppeople
has_many :groupitems

View file

@ -11,6 +11,15 @@ has_many :personitems
has_many :groups, :through => :groupitems
has_many :people, :through => :personitems
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Item'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Item'}
has_many :items1, :through => :synapses2, :source => :item1
has_many :items2, :through => :synapses1, :source => :item2
def siblings
items1 + items2
end
belongs_to :item_category
has_many :child_items, :through => :itemitem_c, :source => :item

View file

@ -6,6 +6,16 @@ has_many :grouppeople
has_many :personitems
has_many :groups, :through => :grouppeople
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', :conditions => {:category => 'Person'}
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', :conditions => {:category => 'Person'}
has_many :people1, :through => :synapses2, :source => :person1
has_many :people2, :through => :synapses1, :source => :person2
def siblings
people1 + people2
end
has_many :items, :through => :personitems
end

14
app/models/synapse.rb Normal file
View file

@ -0,0 +1,14 @@
class Synapse < ActiveRecord::Base
belongs_to :user
belongs_to :item1, :class_name => "Item", :foreign_key => "node1_id"
belongs_to :item2, :class_name => "Item", :foreign_key => "node2_id"
belongs_to :person1, :class_name => "Person", :foreign_key => "node1_id"
belongs_to :person2, :class_name => "Person", :foreign_key => "node2_id"
belongs_to :group1, :class_name => "Group", :foreign_key => "node1_id"
belongs_to :group2, :class_name => "Group", :foreign_key => "node2_id"
end

View file

@ -12,13 +12,13 @@ development:
test:
min_messages: WARNING
adapter: postgresql
host: ec2-54-243-217-241.compute-1.amazonaws.com
host: 127.0.0.1
port: 5432
encoding: unicode
database: dbct9hosrirq2h
database: metamap_test
pool: 5
username: tkbwavghytilon
password: "To6z-64f1Lr3LqpWrcLBPG2Xdv"
username: postgres
password: "3112"
production:
min_messages: WARNING

View file

@ -0,0 +1,13 @@
class CreateSynapses < ActiveRecord::Migration
def change
create_table :synapses do |t|
t.text :desc
t.text :category
t.integer :node1_id
t.integer :node2_id
t.integer :user_id
t.timestamps
end
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120922164150) do
ActiveRecord::Schema.define(:version => 20121005160234) do
create_table "groupgroups", :force => true do |t|
t.integer "group_id"
@ -91,6 +91,16 @@ ActiveRecord::Schema.define(:version => 20120922164150) do
t.datetime "updated_at", :null => false
end
create_table "synapses", :force => true do |t|
t.text "desc"
t.text "category"
t.integer "node1_id"
t.integer "node2_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"

View file

@ -0,0 +1,7 @@
require 'test_helper'
class SynapseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end