Skip to content

Commit 2c3f761

Browse files
committed
Get Author and Authorable interface associations working
1 parent 00951f7 commit 2c3f761

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

app/models/concerns/better_together/author.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ module Author
77

88
included do
99
has_many :authorships,
10-
as: :author
11-
has_many :authorables,
12-
through: :authorships
10+
foreign_key: :author_id
11+
has_many :authored_pages,
12+
through: :authorships,
13+
source: :authorable,
14+
source_type: 'BetterTogether::Page'
15+
has_many :authored_posts,
16+
through: :authorships,
17+
source: :authorable,
18+
source_type: 'BetterTogether::Post'
1319
end
1420
end
1521
end

app/models/concerns/better_together/authorable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Authorable
77

88
included do
99
has_many :authorships,
10+
-> { positioned },
1011
as: :authorable
1112
has_many :authors,
1213
through: :authorships

spec/dummy/db/schema.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@
100100
t.index ["target_locale"], name: "index_better_together_ai_log_translations_on_target_locale"
101101
end
102102

103-
create_table "better_together_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
104-
t.integer "lock_version", default: 0, null: false
105-
t.datetime "created_at", null: false
106-
t.datetime "updated_at", null: false
107-
t.string "author_type", null: false
108-
t.uuid "author_id", null: false
109-
t.index ["author_type", "author_id"], name: "by_author", unique: true
110-
end
111-
112103
create_table "better_together_authorships", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
113104
t.integer "lock_version", default: 0, null: false
114105
t.datetime "created_at", null: false

0 commit comments

Comments
 (0)