ActiveRecord query throught join table and parent_id
I'm studying deeper and deeper RoRails and i am stuck in front of datas we gave me to reproduce on this lovely framework.
Let me show you first my tables and the models associates.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "skills_users", id: false, force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.integer "points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And models:
class Skill < ApplicationRecord
validates :name, presence: true
has_many :children, class_name: "Skill", foreign_key: :parent_id
belongs_to :parent, class_name: "Skill", foreign_key: :parent_id, optional: true
has_and_belongs_to_many :users
end
class User < ApplicationRecord
validates :points, presence: true
has_and_belongs_to_many :skills
end
The goal is to class Skills, fetch Skills children and count Users'points in each parent Skill. Here is an example of data
SKILLS
+-----------------------+
|ID|NAME |PARENT_ID|
+-----------------------+
|1 |Football | |
+-----------------------+
|2 |Basketball| |
+-----------------------+
|3 |Foot |1 |
+-----------------------+
|4 |Basket |2 |
+-----------------------+
|5 |Soccer |1 |
+-----------------------+
SKILLS_USERS
+-------------------+
|ID|SKILL_ID|USER_ID|
+-------------------+
|1 |1 |1 |
+-------------------+
|2 |1 |2 |
+-------------------+
|3 |3 |3 |
+-------------------+
|4 |2 |4 |
+-------------------+
|5 |5 |5 |
+-------------------+
USERS
+---------+
|ID|POINTS|
+---------+
|1 |100 |
+---------+
|2 |200 |
+---------+
|3 |100 |
+---------+
|4 |50 |
+---------+
|5 |10 |
+---------+
The request expected should look like this :
+--------------------------------+
|ID|NAME |POINTS|USERS_COUNT|
+--------------------------------+
|1 |Football |410 |4 |
+--------------------------------+
|2 |Basketball|50 |1 |
+--------------------------------+
I'm trying first to answer it in pure sql with this query:
SELECT id , Name , count ( points) as POINTS , count (USER_ID ) as USERS_COUNT
FROM SKILLS
INNER JOIN SKILLS as SK ON id = SK.parent_id
INNER JOIN SKILLS_USERS AS su ON su.skill_id = id
INNER JOIN USERS AS User ON SU.USER_ID = User.id
But it seems i'm wrong somewhere.
I think ActiveRecord way is much plaisant, ruby is magic. What is the ActiveRecord way to do this kind of request thgrouht to a join table and where we select only parent Skills ?
sql ruby-on-rails relational-database
add a comment |
I'm studying deeper and deeper RoRails and i am stuck in front of datas we gave me to reproduce on this lovely framework.
Let me show you first my tables and the models associates.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "skills_users", id: false, force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.integer "points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And models:
class Skill < ApplicationRecord
validates :name, presence: true
has_many :children, class_name: "Skill", foreign_key: :parent_id
belongs_to :parent, class_name: "Skill", foreign_key: :parent_id, optional: true
has_and_belongs_to_many :users
end
class User < ApplicationRecord
validates :points, presence: true
has_and_belongs_to_many :skills
end
The goal is to class Skills, fetch Skills children and count Users'points in each parent Skill. Here is an example of data
SKILLS
+-----------------------+
|ID|NAME |PARENT_ID|
+-----------------------+
|1 |Football | |
+-----------------------+
|2 |Basketball| |
+-----------------------+
|3 |Foot |1 |
+-----------------------+
|4 |Basket |2 |
+-----------------------+
|5 |Soccer |1 |
+-----------------------+
SKILLS_USERS
+-------------------+
|ID|SKILL_ID|USER_ID|
+-------------------+
|1 |1 |1 |
+-------------------+
|2 |1 |2 |
+-------------------+
|3 |3 |3 |
+-------------------+
|4 |2 |4 |
+-------------------+
|5 |5 |5 |
+-------------------+
USERS
+---------+
|ID|POINTS|
+---------+
|1 |100 |
+---------+
|2 |200 |
+---------+
|3 |100 |
+---------+
|4 |50 |
+---------+
|5 |10 |
+---------+
The request expected should look like this :
+--------------------------------+
|ID|NAME |POINTS|USERS_COUNT|
+--------------------------------+
|1 |Football |410 |4 |
+--------------------------------+
|2 |Basketball|50 |1 |
+--------------------------------+
I'm trying first to answer it in pure sql with this query:
SELECT id , Name , count ( points) as POINTS , count (USER_ID ) as USERS_COUNT
FROM SKILLS
INNER JOIN SKILLS as SK ON id = SK.parent_id
INNER JOIN SKILLS_USERS AS su ON su.skill_id = id
INNER JOIN USERS AS User ON SU.USER_ID = User.id
But it seems i'm wrong somewhere.
I think ActiveRecord way is much plaisant, ruby is magic. What is the ActiveRecord way to do this kind of request thgrouht to a join table and where we select only parent Skills ?
sql ruby-on-rails relational-database
add a comment |
I'm studying deeper and deeper RoRails and i am stuck in front of datas we gave me to reproduce on this lovely framework.
Let me show you first my tables and the models associates.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "skills_users", id: false, force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.integer "points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And models:
class Skill < ApplicationRecord
validates :name, presence: true
has_many :children, class_name: "Skill", foreign_key: :parent_id
belongs_to :parent, class_name: "Skill", foreign_key: :parent_id, optional: true
has_and_belongs_to_many :users
end
class User < ApplicationRecord
validates :points, presence: true
has_and_belongs_to_many :skills
end
The goal is to class Skills, fetch Skills children and count Users'points in each parent Skill. Here is an example of data
SKILLS
+-----------------------+
|ID|NAME |PARENT_ID|
+-----------------------+
|1 |Football | |
+-----------------------+
|2 |Basketball| |
+-----------------------+
|3 |Foot |1 |
+-----------------------+
|4 |Basket |2 |
+-----------------------+
|5 |Soccer |1 |
+-----------------------+
SKILLS_USERS
+-------------------+
|ID|SKILL_ID|USER_ID|
+-------------------+
|1 |1 |1 |
+-------------------+
|2 |1 |2 |
+-------------------+
|3 |3 |3 |
+-------------------+
|4 |2 |4 |
+-------------------+
|5 |5 |5 |
+-------------------+
USERS
+---------+
|ID|POINTS|
+---------+
|1 |100 |
+---------+
|2 |200 |
+---------+
|3 |100 |
+---------+
|4 |50 |
+---------+
|5 |10 |
+---------+
The request expected should look like this :
+--------------------------------+
|ID|NAME |POINTS|USERS_COUNT|
+--------------------------------+
|1 |Football |410 |4 |
+--------------------------------+
|2 |Basketball|50 |1 |
+--------------------------------+
I'm trying first to answer it in pure sql with this query:
SELECT id , Name , count ( points) as POINTS , count (USER_ID ) as USERS_COUNT
FROM SKILLS
INNER JOIN SKILLS as SK ON id = SK.parent_id
INNER JOIN SKILLS_USERS AS su ON su.skill_id = id
INNER JOIN USERS AS User ON SU.USER_ID = User.id
But it seems i'm wrong somewhere.
I think ActiveRecord way is much plaisant, ruby is magic. What is the ActiveRecord way to do this kind of request thgrouht to a join table and where we select only parent Skills ?
sql ruby-on-rails relational-database
I'm studying deeper and deeper RoRails and i am stuck in front of datas we gave me to reproduce on this lovely framework.
Let me show you first my tables and the models associates.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "skills_users", id: false, force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.integer "points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And models:
class Skill < ApplicationRecord
validates :name, presence: true
has_many :children, class_name: "Skill", foreign_key: :parent_id
belongs_to :parent, class_name: "Skill", foreign_key: :parent_id, optional: true
has_and_belongs_to_many :users
end
class User < ApplicationRecord
validates :points, presence: true
has_and_belongs_to_many :skills
end
The goal is to class Skills, fetch Skills children and count Users'points in each parent Skill. Here is an example of data
SKILLS
+-----------------------+
|ID|NAME |PARENT_ID|
+-----------------------+
|1 |Football | |
+-----------------------+
|2 |Basketball| |
+-----------------------+
|3 |Foot |1 |
+-----------------------+
|4 |Basket |2 |
+-----------------------+
|5 |Soccer |1 |
+-----------------------+
SKILLS_USERS
+-------------------+
|ID|SKILL_ID|USER_ID|
+-------------------+
|1 |1 |1 |
+-------------------+
|2 |1 |2 |
+-------------------+
|3 |3 |3 |
+-------------------+
|4 |2 |4 |
+-------------------+
|5 |5 |5 |
+-------------------+
USERS
+---------+
|ID|POINTS|
+---------+
|1 |100 |
+---------+
|2 |200 |
+---------+
|3 |100 |
+---------+
|4 |50 |
+---------+
|5 |10 |
+---------+
The request expected should look like this :
+--------------------------------+
|ID|NAME |POINTS|USERS_COUNT|
+--------------------------------+
|1 |Football |410 |4 |
+--------------------------------+
|2 |Basketball|50 |1 |
+--------------------------------+
I'm trying first to answer it in pure sql with this query:
SELECT id , Name , count ( points) as POINTS , count (USER_ID ) as USERS_COUNT
FROM SKILLS
INNER JOIN SKILLS as SK ON id = SK.parent_id
INNER JOIN SKILLS_USERS AS su ON su.skill_id = id
INNER JOIN USERS AS User ON SU.USER_ID = User.id
But it seems i'm wrong somewhere.
I think ActiveRecord way is much plaisant, ruby is magic. What is the ActiveRecord way to do this kind of request thgrouht to a join table and where we select only parent Skills ?
sql ruby-on-rails relational-database
sql ruby-on-rails relational-database
asked Nov 15 '18 at 21:28
mothinxmothinx
178
178
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If the intended purpose is to record the score of each user for a given skill then you need to place it on the join table and not the users table.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "user_skills", force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.integer "points"
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And you want to setup the associations with has_many through:
and not has_and_belongs_to_many
which does not allow you to query the join table directly or access that points
column.
class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :user
belongs_to :skill
end
class User < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
You query is also much more complex than needed and still misses the mark. You can get the desired result by querying the skills table and joining user_skills
.
SELECT skills.id, skills.name,
SUM(user_skills.points) AS points,
count(user_skills.user_id) AS user_count
FROM "skills"
INNER JOIN "user_skills" ON "user_skills"."skill_id" = "skills"."id"
GROUP BY skills.id
Which we can do in ActiveRecord with:
Skill.joins(:user_skills)
.select('skills.id, skills.name, SUM(user_skills.points) AS points, COUNT(user_skills.user_id) AS user_count')
.group('skills.id')
This will return an ActiveRecord::Relation
of Skill
records with additional .points
and .user_count
attributes.
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
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%2f53328155%2factiverecord-query-throught-join-table-and-parent-id%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the intended purpose is to record the score of each user for a given skill then you need to place it on the join table and not the users table.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "user_skills", force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.integer "points"
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And you want to setup the associations with has_many through:
and not has_and_belongs_to_many
which does not allow you to query the join table directly or access that points
column.
class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :user
belongs_to :skill
end
class User < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
You query is also much more complex than needed and still misses the mark. You can get the desired result by querying the skills table and joining user_skills
.
SELECT skills.id, skills.name,
SUM(user_skills.points) AS points,
count(user_skills.user_id) AS user_count
FROM "skills"
INNER JOIN "user_skills" ON "user_skills"."skill_id" = "skills"."id"
GROUP BY skills.id
Which we can do in ActiveRecord with:
Skill.joins(:user_skills)
.select('skills.id, skills.name, SUM(user_skills.points) AS points, COUNT(user_skills.user_id) AS user_count')
.group('skills.id')
This will return an ActiveRecord::Relation
of Skill
records with additional .points
and .user_count
attributes.
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
add a comment |
If the intended purpose is to record the score of each user for a given skill then you need to place it on the join table and not the users table.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "user_skills", force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.integer "points"
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And you want to setup the associations with has_many through:
and not has_and_belongs_to_many
which does not allow you to query the join table directly or access that points
column.
class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :user
belongs_to :skill
end
class User < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
You query is also much more complex than needed and still misses the mark. You can get the desired result by querying the skills table and joining user_skills
.
SELECT skills.id, skills.name,
SUM(user_skills.points) AS points,
count(user_skills.user_id) AS user_count
FROM "skills"
INNER JOIN "user_skills" ON "user_skills"."skill_id" = "skills"."id"
GROUP BY skills.id
Which we can do in ActiveRecord with:
Skill.joins(:user_skills)
.select('skills.id, skills.name, SUM(user_skills.points) AS points, COUNT(user_skills.user_id) AS user_count')
.group('skills.id')
This will return an ActiveRecord::Relation
of Skill
records with additional .points
and .user_count
attributes.
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
add a comment |
If the intended purpose is to record the score of each user for a given skill then you need to place it on the join table and not the users table.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "user_skills", force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.integer "points"
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And you want to setup the associations with has_many through:
and not has_and_belongs_to_many
which does not allow you to query the join table directly or access that points
column.
class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :user
belongs_to :skill
end
class User < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
You query is also much more complex than needed and still misses the mark. You can get the desired result by querying the skills table and joining user_skills
.
SELECT skills.id, skills.name,
SUM(user_skills.points) AS points,
count(user_skills.user_id) AS user_count
FROM "skills"
INNER JOIN "user_skills" ON "user_skills"."skill_id" = "skills"."id"
GROUP BY skills.id
Which we can do in ActiveRecord with:
Skill.joins(:user_skills)
.select('skills.id, skills.name, SUM(user_skills.points) AS points, COUNT(user_skills.user_id) AS user_count')
.group('skills.id')
This will return an ActiveRecord::Relation
of Skill
records with additional .points
and .user_count
attributes.
If the intended purpose is to record the score of each user for a given skill then you need to place it on the join table and not the users table.
create_table "skills", force: :cascade do |t|
t.string "name"
t.bigint "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["parent_id"], name: "index_skills_on_parent_id"
end
create_table "user_skills", force: :cascade do |t|
t.bigint "skill_id", null: false
t.bigint "user_id", null: false
t.integer "points"
t.index ["skill_id", "user_id"], name: "index_skills_users_on_skill_id_and_user_id"
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
And you want to setup the associations with has_many through:
and not has_and_belongs_to_many
which does not allow you to query the join table directly or access that points
column.
class Skill < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :user
belongs_to :skill
end
class User < ApplicationRecord
has_many :user_skills
has_many :users, through: :user_skills
end
You query is also much more complex than needed and still misses the mark. You can get the desired result by querying the skills table and joining user_skills
.
SELECT skills.id, skills.name,
SUM(user_skills.points) AS points,
count(user_skills.user_id) AS user_count
FROM "skills"
INNER JOIN "user_skills" ON "user_skills"."skill_id" = "skills"."id"
GROUP BY skills.id
Which we can do in ActiveRecord with:
Skill.joins(:user_skills)
.select('skills.id, skills.name, SUM(user_skills.points) AS points, COUNT(user_skills.user_id) AS user_count')
.group('skills.id')
This will return an ActiveRecord::Relation
of Skill
records with additional .points
and .user_count
attributes.
edited Nov 16 '18 at 7:28
answered Nov 16 '18 at 7:23
maxmax
45.5k859103
45.5k859103
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
add a comment |
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Joining the "parent" and "child" skills together and getting a collective aggregate is much more complex and will most likely require a db specific solution to perform it effectively.
– max
Nov 16 '18 at 7:38
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
Thank you max, i will try your solution this afternoon !
– mothinx
Nov 18 '18 at 11:01
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.
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%2f53328155%2factiverecord-query-throught-join-table-and-parent-id%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