Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed the memberships join relation to bento_memberships.

To avoid conflicts with apps that already has a
memberships model.
  • Loading branch information...
commit e6fff77d9108d6acc55f25979fc0c8a7f11a2aff 1 parent d6438cd
Nicklas Ramhöj authored
View
4 README.rdoc
@@ -15,8 +15,8 @@ This will create a model (if one does not exist) and configure it with default B
The generator will also create a migration file (if you're running ActiveRecord) and configure your routes.
The migration files will by default set up the following database structure:
- user has_many :accounts, :through => :memberships
- accounts has_many :users, :through => :memberships
+ user has_many :accounts, :through => :bento_memberships
+ accounts has_many :users, :through => :bento_memberships
== Getting started
=== Model
View
4 lib/bento/models/modules/user_association.rb
@@ -4,8 +4,8 @@ module Modules
module UserAssociation
def self.included(base)
base.class_eval do
- has_many :memberships
- has_many :users, :through => :memberships
+ has_many :bento_memberships
+ has_many :users, :through => :bento_memberships
end
end
end
View
6 lib/generators/active_record/bento_generator.rb
@@ -11,18 +11,18 @@ class BentoGenerator < ActiveRecord::Generators::Base
def generate_model
invoke "active_record:model", [name], :migration => false unless model_exists?
- create_file "app/models/membership.rb", membership_model_content
+ create_file "app/models/bento_membership.rb", bento_membership_model_content
end
def copy_bento_migration
migration_template "create_migration.rb", "db/migrate/bento_create_#{table_name}"
- migration_template "membership_migration.rb", "db/migrate/bento_create_memberships"
+ migration_template "bento_membership_migration.rb", "db/migrate/bento_create_bento_memberships"
end
def inject_bento_content
inject_into_class model_path, class_name, model_contents
inject_into_class user_path, "User", user_model_content
- inject_into_class membership_path, "Membership", membership_model_content
+ inject_into_class bento_membership_path, "BentoMembership", bento_membership_model_content
end
end
end
View
8 ..._record/templates/membership_migration.rb → ...d/templates/bento_membership_migration.rb
@@ -1,12 +1,12 @@
-class BentoCreateMemberships < ActiveRecord::Migration
+class BentoCreateBentoMemberships < ActiveRecord::Migration
def self.up
- create_table :memberships do |t|
+ create_table :bento_memberships do |t|
t.integer :<%= name %>_id
t.integer :user_id
t.timestamps
end
- add_index :memberships, [:<%= name %>_id, :user_id], :unique => true
+ add_index :bento_memberships, [:<%= name %>_id, :user_id], :unique => true
# If you know for sure that you don't want to be able
# to have users that belongs to several <%= name.pluralize %>
@@ -17,7 +17,7 @@ def self.up
end
def self.down
- drop_table :memberships
+ drop_table :bento_memberships
# remove_column :users, :<%= name %>_id
# remove_index :users, :<%= name %>_id
View
18 lib/generators/bento/orm_helpers.rb
@@ -14,8 +14,8 @@ def model_contents
def user_model_content
<<-CONTENT
- has_many :memberships
- has_many :#{table_name}, :through => :memberships
+ has_many :bento_memberships
+ has_many :#{table_name}, :through => :bento_memberships
#
# Remove these methods unless you want to work with
@@ -25,7 +25,7 @@ def user_model_content
# If you know for sure that you don't want to be able
# to have users that belongs to several #{table_name} you
# can of course edit the generated migration files to
- # not create the join model table "memberships" and instead
+ # not create the join model table "bento_memberships" and instead
# add a #{class_name.underscore}_id to your User model.
#
# You also need to not use the :user_association module in bento
@@ -46,9 +46,9 @@ def #{class_name.underscore}=(new_#{class_name.underscore})
CONTENT
end
- def membership_model_content
+ def bento_membership_model_content
<<-CONTENT
-class Membership < ActiveRecord::Base
+class BentoMembership < ActiveRecord::Base
belongs_to :user
belongs_to :#{class_name.underscore}
@@ -61,16 +61,16 @@ def model_exists?
File.exists?(File.join(destination_root, model_path))
end
- def membership_exists?
- File.exists?(File.join(destination_root, membership_path))
+ def bento_membership_exists?
+ File.exists?(File.join(destination_root, bento_membership_path))
end
def model_path
@model_path ||= File.join("app", "models", "#{file_path}.rb")
end
- def membership_path
- @membership_path ||= File.join("app", "models", "membership.rb")
+ def bento_membership_path
+ @bento_membership_path ||= File.join("app", "models", "bento_membership.rb")
end
def user_path
View
2  spec/bento/models/modules/user_accessors_spec.rb
@@ -10,7 +10,7 @@ class UserAccessorsTestAccount < ActiveRecord::Base
before do
# Adding alias to get the relations to work with our custom made class
- Membership.class_eval do
+ BentoMembership.class_eval do
attr_accessible :user_accessors_test_account_id
def user_accessors_test_account_id=(id)
self.account_id = id
View
2  spec/rails_app/app/models/membership.rb → .../rails_app/app/models/bento_membership.rb
@@ -1,4 +1,4 @@
-class Membership < ActiveRecord::Base
+class BentoMembership < ActiveRecord::Base
belongs_to :user
belongs_to :account
View
4 spec/rails_app/app/models/user.rb
@@ -6,8 +6,8 @@ class User < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :account
belongs_to :site
- has_many :memberships
- has_many :accounts, :through => :memberships
+ has_many :bento_memberships
+ has_many :accounts, :through => :bento_memberships
# TODO: move these to a bento module
def account
View
25 spec/rails_app/db/migrate/20110821095924_bento_create_bento_memberships.rb
@@ -0,0 +1,25 @@
+class BentoCreateBentoMemberships < ActiveRecord::Migration
+ def self.up
+ create_table :bento_memberships do |t|
+ t.integer :account_id
+ t.integer :user_id
+ t.timestamps
+ end
+
+ add_index :bento_memberships, [:account_id, :user_id], :unique => true
+
+ # If you know for sure that you don't want to be able
+ # to have users that belongs to several accounts
+ # please remove the above lines and uncomment the lines below
+
+ # add_column :users, :account_id, :integer
+ # add_index :users, :account_id
+ end
+
+ def self.down
+ drop_table :bento_memberships
+
+ # remove_column :users, :account_id
+ # remove_index :users, :account_id
+ end
+end
View
15 spec/rails_app/db/migrate/20110821095924_bento_create_memberships.rb
@@ -1,15 +0,0 @@
-class BentoCreateMemberships < ActiveRecord::Migration
- def self.up
- create_table :memberships do |t|
- t.integer :account_id
- t.integer :user_id
- t.timestamps
- end
-
- add_index :memberships, [:account_id, :user_id], :unique => true
- end
-
- def self.down
- drop_table :memberships
- end
-end
View
6 spec/rails_app/db/schema.rb
@@ -21,14 +21,14 @@
add_index "accounts", ["name"], :name => "index_accounts_on_name", :unique => true
- create_table "memberships", :force => true do |t|
+ create_table "bento_memberships", :force => true do |t|
t.integer "account_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "memberships", ["account_id", "user_id"], :name => "index_memberships_on_account_id_and_user_id", :unique => true
+ add_index "bento_memberships", ["account_id", "user_id"], :name => "index_bento_memberships_on_account_id_and_user_id", :unique => true
create_table "projects", :force => true do |t|
t.string "name"
@@ -53,8 +53,8 @@
t.string "last_name"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "site_id"
t.integer "account_id"
+ t.integer "site_id"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
Please sign in to comment.
Something went wrong with that request. Please try again.