浏览代码

team: member dependent destroy

Lou 3 年前
父节点
当前提交
965dad1401
共有 3 个文件被更改,包括 52 次插入52 次删除
  1. 2
    2
      app/models/membership.rb
  2. 6
    6
      app/models/team.rb
  3. 44
    44
      config/application.rb

+ 2
- 2
app/models/membership.rb 查看文件

@@ -1,6 +1,6 @@
1 1
 class Membership < ApplicationRecord
2
-  attr_readonly :member
3
-  attr_readonly :team
2
+  # attr_readonly :member
3
+  # attr_readonly :team
4 4
 
5 5
   validates :member, presence: :true
6 6
   validates :team, presence: :true

+ 6
- 6
app/models/team.rb 查看文件

@@ -1,6 +1,6 @@
1
-class Team < ApplicationRecord
2
-    validates :name, uniqueness: true, presence: true
3
-
4
-    has_many :memberships
5
-    has_many :users, through: :memberships
6
-end
1
+class Team < ApplicationRecord
2
+    validates :name, uniqueness: true, presence: true
3
+
4
+    has_many :memberships
5
+    has_many :members, through: :memberships, dependent: :destroy
6
+end

+ 44
- 44
config/application.rb 查看文件

@@ -1,44 +1,44 @@
1
-require_relative "boot"
2
-
3
-require "rails"
4
-# Pick the frameworks you want:
5
-require "active_model/railtie"
6
-require "active_job/railtie"
7
-require "active_record/railtie"
8
-require "active_storage/engine"
9
-require "action_controller/railtie"
10
-require "action_mailer/railtie"
11
-require "action_mailbox/engine"
12
-require "action_text/engine"
13
-require "action_view/railtie"
14
-require "action_cable/engine"
15
-# require "sprockets/railtie"
16
-require "rails/test_unit/railtie"
17
-
18
-# Require the gems listed in Gemfile, including any gems
19
-# you've limited to :test, :development, or :production.
20
-Bundler.require(*Rails.groups)
21
-
22
-module ChronobriqApi
23
-  class Application < Rails::Application
24
-    # Initialize configuration defaults for originally generated Rails version.
25
-    config.load_defaults 6.1
26
-
27
-    # Configuration for the application, engines, and railties goes here.
28
-    #
29
-    # These settings can be overridden in specific environments using the files
30
-    # in config/environments, which are processed later.
31
-    #
32
-    # config.time_zone = "Central Time (US & Canada)"
33
-    # config.eager_load_paths << Rails.root.join("extras")
34
-
35
-    # Only loads a smaller set of middleware suitable for API only apps.
36
-    # Middleware like session, flash, cookies can be added back manually.
37
-    # Skip views, helpers and assets when generating a new resource.
38
-    config.api_only = true
39
-
40
-    # Adds the content of 'lib' folder to Ruby on Rails _autoload_s,
41
-    # used to handle tokens.
42
-    config.eager_load_paths << Rails.root.join('lib')
43
-  end
44
-end
1
+require_relative "boot"
2
+
3
+require "rails"
4
+# Pick the frameworks you want:
5
+require "active_model/railtie"
6
+require "active_job/railtie"
7
+require "active_record/railtie"
8
+require "active_storage/engine"
9
+require "action_controller/railtie"
10
+require "action_mailer/railtie"
11
+require "action_mailbox/engine"
12
+require "action_text/engine"
13
+require "action_view/railtie"
14
+require "action_cable/engine"
15
+# require "sprockets/railtie"
16
+require "rails/test_unit/railtie"
17
+
18
+# Require the gems listed in Gemfile, including any gems
19
+# you've limited to :test, :development, or :production.
20
+Bundler.require(*Rails.groups)
21
+
22
+module ChronobriqApi
23
+  class Application < Rails::Application
24
+    # Initialize configuration defaults for originally generated Rails version.
25
+    config.load_defaults 6.1
26
+
27
+    # Configuration for the application, engines, and railties goes here.
28
+    #
29
+    # These settings can be overridden in specific environments using the files
30
+    # in config/environments, which are processed later.
31
+    #
32
+    # config.time_zone = "Central Time (US & Canada)"
33
+    # config.eager_load_paths << Rails.root.join("extras")
34
+
35
+    # Only loads a smaller set of middleware suitable for API only apps.
36
+    # Middleware like session, flash, cookies can be added back manually.
37
+    # Skip views, helpers and assets when generating a new resource.
38
+    config.api_only = true
39
+
40
+    # Adds the content of 'lib' folder to Ruby on Rails _autoload_s,
41
+    # used to handle tokens.
42
+    config.eager_load_paths << Rails.root.join('lib')
43
+  end
44
+end

正在加载...
取消
保存