Skip to content

Commit

Permalink
Added ItemGroup model
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoynter committed May 17, 2017
1 parent 61f7c36 commit c42c27a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/models/item_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ItemGroup < ApplicationRecord
belongs_to :item, polymorphic: true
belongs_to :root_item, polymorphic: true

enum group_type: [:similar, :identical]
end
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class User < ApplicationRecord
belongs_to :group
belongs_to :user_group

delegate :study, to: :group
delegate :study, to: :user_group

# Others available are:
# :timeoutable and :omniauthable
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserGroup < ApplicationRecord

private # Private methods

# In case more than just the study label is submitted extract the label for
# In case more than just the study label is submitted extract the label from
# saving
def remove_study_labelling
if study.is_a? Array
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20170517153047_create_item_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateItemGroups < ActiveRecord::Migration[5.0]
def change
create_table :item_groups do |t|
t.references :item, polymorphic: true
t.integer :group_type
t.references :root_item, polymorphic: true

t.timestamps
end
end
end
67 changes: 66 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,41 @@ CREATE SEQUENCE instruments_id_seq
ALTER SEQUENCE instruments_id_seq OWNED BY instruments.id;


--
-- Name: item_groups; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE item_groups (
id integer NOT NULL,
item_type character varying,
item_id integer,
group_type integer,
root_item_type character varying,
root_item_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


--
-- Name: item_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE item_groups_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: item_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE item_groups_id_seq OWNED BY item_groups.id;


--
-- Name: links; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1221,6 +1256,13 @@ ALTER TABLE ONLY instruments ALTER COLUMN id SET DEFAULT nextval('instruments_id
ALTER TABLE ONLY instruments_datasets ALTER COLUMN id SET DEFAULT nextval('instruments_datasets_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY item_groups ALTER COLUMN id SET DEFAULT nextval('item_groups_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1495,6 +1537,14 @@ ALTER TABLE ONLY instruments
ADD CONSTRAINT instruments_pkey PRIMARY KEY (id);


--
-- Name: item_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY item_groups
ADD CONSTRAINT item_groups_pkey PRIMARY KEY (id);


--
-- Name: links_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1804,6 +1854,20 @@ CREATE INDEX index_instruments_datasets_on_dataset_id ON instruments_datasets US
CREATE INDEX index_instruments_datasets_on_instrument_id ON instruments_datasets USING btree (instrument_id);


--
-- Name: index_item_groups_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_item_groups_on_item_type_and_item_id ON item_groups USING btree (item_type, item_id);


--
-- Name: index_item_groups_on_root_item_type_and_root_item_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_item_groups_on_root_item_type_and_root_item_id ON item_groups USING btree (root_item_type, root_item_id);


--
-- Name: index_links_on_target_type_and_target_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -2332,6 +2396,7 @@ INSERT INTO schema_migrations (version) VALUES
('20170302132603'),
('20170302132849'),
('20170505135010'),
('20170517105644');
('20170517105644'),
('20170517153047');


15 changes: 15 additions & 0 deletions test/fixtures/item_groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
item: one
item_type: Item
group_type: MyString
root_item: one
root_item_type: Root item

two:
item: two
item_type: Item
group_type: MyString
root_item: two
root_item_type: Root item
7 changes: 7 additions & 0 deletions test/models/item_group_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ItemGroupTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit c42c27a

Please sign in to comment.