Skip to content

Instantly share code, notes, and snippets.

@nviennot
Created November 6, 2019 02:58
Show Gist options
  • Save nviennot/9f636ff7ce952ec9e10001e0aabd7a4a to your computer and use it in GitHub Desktop.
Save nviennot/9f636ff7ce952ec9e10001e0aabd7a4a to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.require
NoBrainer.configure do |config|
config.app_name = 'test'
config.environment = 'dev'
config.logger = Logger.new(STDERR).tap { |l| l.level = Logger::DEBUG }
end
NoBrainer.drop!
# Organisation model
class Organisation
include NoBrainer::Document
include NoBrainer::Document::Timestamps
# include HasSlug
# ~~~~ Virtual Fields ~~~~
attr_accessor :remove_logo
# ~~~~ Fieds ~~~~~
field :name, type: String, uniq: true, required: true
field :logo, type: String
field :postal_code, type: String
field :city, type: String
field :street, type: String
field :email, type: String
field :billing_email, type: String
field :slug, type: String, uniq: true, required: true
# ~~~~ Special Behaviors ~~~~
# mount_uploader :logo, LogoUploader
# ~~~~ Associations ~~~~
belongs_to :created_by_user, class_name: 'User'
belongs_to :country, validates: false
has_many :clients
has_many :ideas
has_many :join_requests
has_many :notifications
has_many :projects
has_many :tags
has_many :users
# Simple index
index :name
def to_param
slug
end
end
class Project
include NoBrainer::Document
include NoBrainer::Document::Timestamps
# ~~~~ Virtual Fields ~~~~
attr_accessor :remove_picture
# ~~~~ Fieds ~~~~~
field :logo, type: String
field :name, type: String, required: true, uniq: { scope: :organisation_id }
field :organisation_id, type: String
field :created_by_user_id, type: String
field :slug, type: String, uniq: true, required: true
field :state, type: String
# ~~~~ Associations ~~~~
belongs_to :created_by_user, class_name: 'User'
belongs_to :organisation
has_many :ideas
# Simple index
index :name
# ~~~~ Special Behaviors ~~~~
end
NoBrainer.sync_schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment