Skip to content

Commit

Permalink
prepare to implementation case 05
Browse files Browse the repository at this point in the history
  • Loading branch information
nlevchuk committed Jun 8, 2012
1 parent e3af0bc commit c22c659
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 11 deletions.
15 changes: 15 additions & 0 deletions app/active_record/questions_answeroptions_answers/answer.rb
@@ -0,0 +1,15 @@
# encoding: utf-8
class Answer < ActiveRecord::Base
attr_accessible :questions_answer_option_id
belongs_to :place
belongs_to :questions_answer_option
# belongs_to :question, :through => :questions_answer_option
# belongs_to :answer_option, :through => :questions_answer_option
def question
questions_answer_option.question
end

def answer
questions_answer_option.answer_option
end
end
@@ -0,0 +1,5 @@
# encoding: utf-8
class AnswerOption < ActiveRecord::Base
attr_accessible :title
has_many :questions_answer_options
end
@@ -0,0 +1,6 @@
class CategoriesPlace < ActiveRecord::Base
attr_accessible :place_id, :category_id
belongs_to :category
belongs_to :place
has_many :questions
end
8 changes: 8 additions & 0 deletions app/active_record/questions_answeroptions_answers/category.rb
@@ -0,0 +1,8 @@
# encoding: utf-8
class Category < ActiveRecord::Base
attr_accessible :name
has_many :categories_places
has_many :places, :through => :categories_places
has_many :questions, :through => :categories_places
# has_and_belongs_to_many :questions
end
5 changes: 5 additions & 0 deletions app/active_record/questions_answeroptions_answers/place.rb
@@ -0,0 +1,5 @@
# encoding: utf-8
class Place < ActiveRecord::Base
attr_accessible :address
has_many :answers
end
6 changes: 6 additions & 0 deletions app/active_record/questions_answeroptions_answers/question.rb
@@ -0,0 +1,6 @@
# encoding: utf-8
class Question < ActiveRecord::Base
attr_accessible :title
has_many :questions_answer_options
has_many :answer_options, :through => :questions_answer_options
end
@@ -0,0 +1,6 @@
# encoding: utf-8
class QuestionsAnswerOption < ActiveRecord::Base
has_one :answer
belongs_to :question
belongs_to :answer_option
end
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
8 changes: 4 additions & 4 deletions config/application.rb
Expand Up @@ -17,7 +17,7 @@
module Arvsmongo
class Application < Rails::Application

config.mongoid.logger = Logger.new($stdout, :all)
# config.mongoid.logger = Logger.new($stdout, :all)
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand All @@ -29,13 +29,13 @@ class Application < Rails::Application
# config.autoload_paths += %W(#{config.root}/app/mongoid/place_category)
# config.autoload_paths += %W(#{config.root}/app/mongoid/place_user_review)
# config.autoload_paths += %W(#{config.root}/app/mongoid/review_comment_user)
# config.autoload_paths += %W(#{config.root}/app/mongoid/place_review_moderator)
# config.autoload_paths += %W(#{config.root}/app/mongoid/questions_answeroptions_answers)

# config.autoload_paths += %W(#{config.root}/app/active_record/place_city_country)
# config.autoload_paths += %W(#{config.root}/app/active_record/place_category)
# config.autoload_paths += %W(#{config.root}/app/active_record/place_user_review)
config.autoload_paths += %W(#{config.root}/app/active_record/review_comment_user)
# config.autoload_paths += %W(#{config.root}/app/active_record/place_review_moderator)
# config.autoload_paths += %W(#{config.root}/app/active_record/review_comment_user)
config.autoload_paths += %W(#{config.root}/app/active_record/questions_answeroptions_answers)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down
@@ -1,6 +1,6 @@
class CreateJoinTableForCategoriesAndPlaces < ActiveRecord::Migration
def self.up
create_table :categories_places, :id => false do |t|
create_table :categories_places do |t|
t.integer :place_id
t.integer :category_id
end
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20120608050752_create_table_questions.rb
@@ -0,0 +1,11 @@
class CreateTableQuestions < ActiveRecord::Migration
def up
create_table :questions do |t|
t.string :title
end
end

def down
drop_table :questions
end
end
@@ -0,0 +1,11 @@
class CreateJoinTableForQuestionsAndAnswerOptions < ActiveRecord::Migration
def up
create_table :questions_answer_options do |t|
t.integer :question_id
t.integer :answer_option_id
end
end

def down
end
end
12 changes: 12 additions & 0 deletions db/migrate/20120608085929_create_table_answers.rb
@@ -0,0 +1,12 @@
class CreateTableAnswers < ActiveRecord::Migration
def up
create_table :answers do |t|
t.references :place
t.references :questions_answer_option
end
end

def down
drop_table :answers
end
end
11 changes: 11 additions & 0 deletions db/migrate/20120608085939_create_table_answer_options.rb
@@ -0,0 +1,11 @@
class CreateTableAnswerOptions < ActiveRecord::Migration
def up
create_table :answer_options do |t|
t.string :title
end
end

def down
drop_table :answer_options
end
end
23 changes: 21 additions & 2 deletions db/schema.rb
Expand Up @@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120607100718) do
ActiveRecord::Schema.define(:version => 20120608085939) do

create_table "answer_options", :force => true do |t|
t.string "title"
end

create_table "answers", :force => true do |t|
t.integer "place_id"
t.integer "questions_answer_option_id"
end

create_table "categories", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -44,6 +53,17 @@
t.integer "city_id"
end

add_index "places", ["city_id"], :name => "index_city_for_place"

create_table "questions", :force => true do |t|
t.string "title"
end

create_table "questions_answer_options", :force => true do |t|
t.integer "question_id"
t.integer "answer_option_id"
end

create_table "reviews", :force => true do |t|
t.string "title"
t.text "description"
Expand All @@ -54,5 +74,4 @@
t.string "name"
end

add_index "places", ["city_id"], :name => "index_city_for_place"
end
8 changes: 4 additions & 4 deletions lib/tasks/populate_case02.rake
Expand Up @@ -19,13 +19,13 @@ namespace :db do
}]

iterations.each do |iteration|
# Place.first(iteration[:records]).each do |place| # AR
Place.limit(iteration[:records]).each do |place| # Mongo
Place.first(iteration[:records]).each do |place| # AR
# Place.limit(iteration[:records]).each do |place| # Mongo
categories_count = iteration[:categories]
categories_count.times do
skip = rand(Category.count)
# random_category = Category.first(:offset => skip) # AR
random_category = Category.first(:skip => skip) # Mongo
random_category = Category.first(:offset => skip) # AR
# random_category = Category.first(:skip => skip) # Mongo
place.categories << random_category unless place.category_ids.include?(random_category.id)
end
end
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/populate_case05.rake
@@ -0,0 +1,10 @@
namespace :db do
desc "populate Questions model"
task :populate_questions => :environment do

Question.delete_all
['wifi','toilet','music','smoking','bank card'].each do |item|
Question.create(:title => item)
end
end
end

0 comments on commit c22c659

Please sign in to comment.