added ability to create synapses between nodes of same type
This commit is contained in:
parent
a7d89bf798
commit
ca2898fe3d
8 changed files with 77 additions and 5 deletions
|
@ -4,6 +4,15 @@ belongs_to :user
|
||||||
|
|
||||||
has_many :groupgroup_c, :foreign_key => 'parent_group_id', :class_name => 'Groupgroup'
|
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 :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 :grouppeople
|
||||||
has_many :groupitems
|
has_many :groupitems
|
||||||
|
|
|
@ -11,6 +11,15 @@ has_many :personitems
|
||||||
has_many :groups, :through => :groupitems
|
has_many :groups, :through => :groupitems
|
||||||
has_many :people, :through => :personitems
|
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
|
belongs_to :item_category
|
||||||
|
|
||||||
has_many :child_items, :through => :itemitem_c, :source => :item
|
has_many :child_items, :through => :itemitem_c, :source => :item
|
||||||
|
|
|
@ -6,6 +6,16 @@ has_many :grouppeople
|
||||||
has_many :personitems
|
has_many :personitems
|
||||||
|
|
||||||
has_many :groups, :through => :grouppeople
|
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
|
has_many :items, :through => :personitems
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
14
app/models/synapse.rb
Normal file
14
app/models/synapse.rb
Normal 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
|
|
@ -12,13 +12,13 @@ development:
|
||||||
test:
|
test:
|
||||||
min_messages: WARNING
|
min_messages: WARNING
|
||||||
adapter: postgresql
|
adapter: postgresql
|
||||||
host: ec2-54-243-217-241.compute-1.amazonaws.com
|
host: 127.0.0.1
|
||||||
port: 5432
|
port: 5432
|
||||||
encoding: unicode
|
encoding: unicode
|
||||||
database: dbct9hosrirq2h
|
database: metamap_test
|
||||||
pool: 5
|
pool: 5
|
||||||
username: tkbwavghytilon
|
username: postgres
|
||||||
password: "To6z-64f1Lr3LqpWrcLBPG2Xdv"
|
password: "3112"
|
||||||
|
|
||||||
production:
|
production:
|
||||||
min_messages: WARNING
|
min_messages: WARNING
|
||||||
|
|
13
db/migrate/20121005160234_create_synapses.rb
Normal file
13
db/migrate/20121005160234_create_synapses.rb
Normal 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
|
12
db/schema.rb
12
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "groupgroups", :force => true do |t|
|
||||||
t.integer "group_id"
|
t.integer "group_id"
|
||||||
|
@ -91,6 +91,16 @@ ActiveRecord::Schema.define(:version => 20120922164150) do
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
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|
|
create_table "users", :force => true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "email"
|
t.string "email"
|
||||||
|
|
7
test/unit/synapse_test.rb
Normal file
7
test/unit/synapse_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SynapseTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue