has_one/has_many rails association with alternate source ID other then primary key
I have 3 models.
Model A belongs to model B and model B has many model C
by using through
I can set in model A class has_many :c,through: :b
Now whenever I call a_instance.cs
It would JOIN with table B unnecessarily What I want is direct association of A
& C
using b_id
in both A & C class.
So how can I write a has_one/has_many rails association without through
clause when both Source and Destination entities has same foreign_key of 3rd entity? (b_id
for this example)
class C
belongs_to :b #b_id column is there in DB
end
class B
has_many :cs
end
class A
belongs_to :b #b_id column is there in DB
has_many :cs , through: :b #This is the association in Question
#WHAT I WANT TO DO. So something in place of primary_key which would fetch C class directly.
has_many :cs ,class_name: 'C',foreign_key: 'b_id',primary_key: 'b_id'
end
ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-5
add a comment |
I have 3 models.
Model A belongs to model B and model B has many model C
by using through
I can set in model A class has_many :c,through: :b
Now whenever I call a_instance.cs
It would JOIN with table B unnecessarily What I want is direct association of A
& C
using b_id
in both A & C class.
So how can I write a has_one/has_many rails association without through
clause when both Source and Destination entities has same foreign_key of 3rd entity? (b_id
for this example)
class C
belongs_to :b #b_id column is there in DB
end
class B
has_many :cs
end
class A
belongs_to :b #b_id column is there in DB
has_many :cs , through: :b #This is the association in Question
#WHAT I WANT TO DO. So something in place of primary_key which would fetch C class directly.
has_many :cs ,class_name: 'C',foreign_key: 'b_id',primary_key: 'b_id'
end
ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-5
1
Why is this tagged asruby-on-rails-4
andruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.
– Tom Lord
Oct 22 '18 at 8:20
4
The lasthas_many
withforeign_key
andprimary_key
works for me, what issues are you having? Specifyingclass_name
is not necessary, tested with Rails 5.1.4.
– Marcin Kołodziej
Nov 15 '18 at 18:29
1
Agree, the lasthas_many
works for me and also works w/o theprimary_key
.
– Derek
Nov 20 '18 at 4:22
add a comment |
I have 3 models.
Model A belongs to model B and model B has many model C
by using through
I can set in model A class has_many :c,through: :b
Now whenever I call a_instance.cs
It would JOIN with table B unnecessarily What I want is direct association of A
& C
using b_id
in both A & C class.
So how can I write a has_one/has_many rails association without through
clause when both Source and Destination entities has same foreign_key of 3rd entity? (b_id
for this example)
class C
belongs_to :b #b_id column is there in DB
end
class B
has_many :cs
end
class A
belongs_to :b #b_id column is there in DB
has_many :cs , through: :b #This is the association in Question
#WHAT I WANT TO DO. So something in place of primary_key which would fetch C class directly.
has_many :cs ,class_name: 'C',foreign_key: 'b_id',primary_key: 'b_id'
end
ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-5
I have 3 models.
Model A belongs to model B and model B has many model C
by using through
I can set in model A class has_many :c,through: :b
Now whenever I call a_instance.cs
It would JOIN with table B unnecessarily What I want is direct association of A
& C
using b_id
in both A & C class.
So how can I write a has_one/has_many rails association without through
clause when both Source and Destination entities has same foreign_key of 3rd entity? (b_id
for this example)
class C
belongs_to :b #b_id column is there in DB
end
class B
has_many :cs
end
class A
belongs_to :b #b_id column is there in DB
has_many :cs , through: :b #This is the association in Question
#WHAT I WANT TO DO. So something in place of primary_key which would fetch C class directly.
has_many :cs ,class_name: 'C',foreign_key: 'b_id',primary_key: 'b_id'
end
ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-5
ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-5
asked Oct 22 '18 at 8:09
Qaisar Nadeem
1,815718
1,815718
1
Why is this tagged asruby-on-rails-4
andruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.
– Tom Lord
Oct 22 '18 at 8:20
4
The lasthas_many
withforeign_key
andprimary_key
works for me, what issues are you having? Specifyingclass_name
is not necessary, tested with Rails 5.1.4.
– Marcin Kołodziej
Nov 15 '18 at 18:29
1
Agree, the lasthas_many
works for me and also works w/o theprimary_key
.
– Derek
Nov 20 '18 at 4:22
add a comment |
1
Why is this tagged asruby-on-rails-4
andruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.
– Tom Lord
Oct 22 '18 at 8:20
4
The lasthas_many
withforeign_key
andprimary_key
works for me, what issues are you having? Specifyingclass_name
is not necessary, tested with Rails 5.1.4.
– Marcin Kołodziej
Nov 15 '18 at 18:29
1
Agree, the lasthas_many
works for me and also works w/o theprimary_key
.
– Derek
Nov 20 '18 at 4:22
1
1
Why is this tagged as
ruby-on-rails-4
and ruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.– Tom Lord
Oct 22 '18 at 8:20
Why is this tagged as
ruby-on-rails-4
and ruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.– Tom Lord
Oct 22 '18 at 8:20
4
4
The last
has_many
with foreign_key
and primary_key
works for me, what issues are you having? Specifying class_name
is not necessary, tested with Rails 5.1.4.– Marcin Kołodziej
Nov 15 '18 at 18:29
The last
has_many
with foreign_key
and primary_key
works for me, what issues are you having? Specifying class_name
is not necessary, tested with Rails 5.1.4.– Marcin Kołodziej
Nov 15 '18 at 18:29
1
1
Agree, the last
has_many
works for me and also works w/o the primary_key
.– Derek
Nov 20 '18 at 4:22
Agree, the last
has_many
works for me and also works w/o the primary_key
.– Derek
Nov 20 '18 at 4:22
add a comment |
2 Answers
2
active
oldest
votes
An example, Teacher and Student models belong to Group, Teacher has many Student:
class Group < ApplicationRecord
has_many :teachers
has_many :students
end
class Teacher < ApplicationRecord
belongs_to :group
has_many :students, :foreign_key => 'group_id', :primary_key => 'group_id'
end
class Student < ApplicationRecord
belongs_to :group
end
And you can retrieve a teacher's students in a group like this:
teacher = Teacher.find(:teacher_id)
students = teacher.students
add a comment |
Following your example of classes A,B & C and changing only the implementation of class A.
class A
belongs_to :b
def cs
self.id = b_id
b_cast = self.becomes(B)
b_cast.cs
end
end
Console
A.first ==>#<A id: 105, b_id: 1 ...>
B.first ==>#<B id: 1 ...>
C.all ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
A.first.cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
A.first.cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Official #becomes(klass) documentation can be found
here!
On other end, the same effect can be achieved creating an instance of the class B and giving it the id stored in A.first.b_id as follows:
B.new(id: A.first.b_id).cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
B.new(id: A.first.b_id).cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52924841%2fhas-one-has-many-rails-association-with-alternate-source-id-other-then-primary-k%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
An example, Teacher and Student models belong to Group, Teacher has many Student:
class Group < ApplicationRecord
has_many :teachers
has_many :students
end
class Teacher < ApplicationRecord
belongs_to :group
has_many :students, :foreign_key => 'group_id', :primary_key => 'group_id'
end
class Student < ApplicationRecord
belongs_to :group
end
And you can retrieve a teacher's students in a group like this:
teacher = Teacher.find(:teacher_id)
students = teacher.students
add a comment |
An example, Teacher and Student models belong to Group, Teacher has many Student:
class Group < ApplicationRecord
has_many :teachers
has_many :students
end
class Teacher < ApplicationRecord
belongs_to :group
has_many :students, :foreign_key => 'group_id', :primary_key => 'group_id'
end
class Student < ApplicationRecord
belongs_to :group
end
And you can retrieve a teacher's students in a group like this:
teacher = Teacher.find(:teacher_id)
students = teacher.students
add a comment |
An example, Teacher and Student models belong to Group, Teacher has many Student:
class Group < ApplicationRecord
has_many :teachers
has_many :students
end
class Teacher < ApplicationRecord
belongs_to :group
has_many :students, :foreign_key => 'group_id', :primary_key => 'group_id'
end
class Student < ApplicationRecord
belongs_to :group
end
And you can retrieve a teacher's students in a group like this:
teacher = Teacher.find(:teacher_id)
students = teacher.students
An example, Teacher and Student models belong to Group, Teacher has many Student:
class Group < ApplicationRecord
has_many :teachers
has_many :students
end
class Teacher < ApplicationRecord
belongs_to :group
has_many :students, :foreign_key => 'group_id', :primary_key => 'group_id'
end
class Student < ApplicationRecord
belongs_to :group
end
And you can retrieve a teacher's students in a group like this:
teacher = Teacher.find(:teacher_id)
students = teacher.students
answered Nov 20 '18 at 7:44
Gentry Chen
1,284814
1,284814
add a comment |
add a comment |
Following your example of classes A,B & C and changing only the implementation of class A.
class A
belongs_to :b
def cs
self.id = b_id
b_cast = self.becomes(B)
b_cast.cs
end
end
Console
A.first ==>#<A id: 105, b_id: 1 ...>
B.first ==>#<B id: 1 ...>
C.all ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
A.first.cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
A.first.cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Official #becomes(klass) documentation can be found
here!
On other end, the same effect can be achieved creating an instance of the class B and giving it the id stored in A.first.b_id as follows:
B.new(id: A.first.b_id).cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
B.new(id: A.first.b_id).cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
add a comment |
Following your example of classes A,B & C and changing only the implementation of class A.
class A
belongs_to :b
def cs
self.id = b_id
b_cast = self.becomes(B)
b_cast.cs
end
end
Console
A.first ==>#<A id: 105, b_id: 1 ...>
B.first ==>#<B id: 1 ...>
C.all ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
A.first.cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
A.first.cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Official #becomes(klass) documentation can be found
here!
On other end, the same effect can be achieved creating an instance of the class B and giving it the id stored in A.first.b_id as follows:
B.new(id: A.first.b_id).cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
B.new(id: A.first.b_id).cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
add a comment |
Following your example of classes A,B & C and changing only the implementation of class A.
class A
belongs_to :b
def cs
self.id = b_id
b_cast = self.becomes(B)
b_cast.cs
end
end
Console
A.first ==>#<A id: 105, b_id: 1 ...>
B.first ==>#<B id: 1 ...>
C.all ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
A.first.cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
A.first.cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Official #becomes(klass) documentation can be found
here!
On other end, the same effect can be achieved creating an instance of the class B and giving it the id stored in A.first.b_id as follows:
B.new(id: A.first.b_id).cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
B.new(id: A.first.b_id).cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Following your example of classes A,B & C and changing only the implementation of class A.
class A
belongs_to :b
def cs
self.id = b_id
b_cast = self.becomes(B)
b_cast.cs
end
end
Console
A.first ==>#<A id: 105, b_id: 1 ...>
B.first ==>#<B id: 1 ...>
C.all ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
A.first.cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
A.first.cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
Official #becomes(klass) documentation can be found
here!
On other end, the same effect can be achieved creating an instance of the class B and giving it the id stored in A.first.b_id as follows:
B.new(id: A.first.b_id).cs
A Load (0.2ms) SELECT "as".* FROM "as" ORDER BY "as"."id" ASC LIMIT ? [["LIMIT", 1]]
C Load (0.1ms) SELECT "cs".* FROM "cs" WHERE "cs"."b_id" = ? LIMIT ? [["b_id", 1], ["LIMIT", 11]]
B.new(id: A.first.b_id).cs ==>#<C id: 1, b_id: 1 ...>,
#<C id: 2, b_id: 1 ...>,
#<C id: 3, b_id: 1 ...>,
#<C id: 4, b_id: 1 ...>
answered Nov 21 '18 at 21:23
MrCodeX
114
114
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
add a comment |
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
If the solution is necessarily through active records relation point it out so I may remove this answer.
– MrCodeX
Nov 21 '18 at 21:37
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
Thank you for the answer. But Solution regarding AR Association is required. Method base approach can be done in multiple ways but it removes all the flexibility which AR associations provide
– Qaisar Nadeem
Nov 22 '18 at 20:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52924841%2fhas-one-has-many-rails-association-with-alternate-source-id-other-then-primary-k%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why is this tagged as
ruby-on-rails-4
andruby-on-rails-5
? The solution probably doesn't make a difference in this case, but it's advisable to actually specify the version you're using.– Tom Lord
Oct 22 '18 at 8:20
4
The last
has_many
withforeign_key
andprimary_key
works for me, what issues are you having? Specifyingclass_name
is not necessary, tested with Rails 5.1.4.– Marcin Kołodziej
Nov 15 '18 at 18:29
1
Agree, the last
has_many
works for me and also works w/o theprimary_key
.– Derek
Nov 20 '18 at 4:22