How can I get to the third table with an association?accepts_nested_attributes_for child association validation failingHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How can a record belong_to a single user, but also have multiple “secondary” users?Creating Join Tables for has_many & belongs_to AssociationsRails 3 has_many :through is only adding id from on side of the relationshipHowto use callbacks in a has_many through association?how to permit an array with strong parametersHow find record with conditions for joined associationsjoins from belongs_to where query not working
How hard would it be to convert a glider into an powered electric aircraft?
`cosf`, `sinf`, etc. are not in `std`
Version 2 - print new even-length arrays from two arrays
I have a dialogue that I can't write directly. What would be a good alternative?
What are the words for people who cause trouble believing they know better?
Company did not petition for visa in a timely manner. Is asking me to work from overseas, but wants me to take a paycut
Avoiding cliches when writing gods
Where does this pattern of naming products come from?
Implement Homestuck's Catenative Doomsday Dice Cascader
When conversion from Integer to Single may lose precision
Does the "6 seconds per round" rule apply to speaking/roleplaying during combat situations?
How bad would a partial hash leak be, realistically?
Traffic law UK, pedestrians
How is it possible that Gollum speaks Westron?
Question about JavaScript Math.random() and basic logic
Remove sudoers using script
Is it possible to (7 day) schedule sleep time of a hard drive?
Random Portfolios vs Efficient Frontier
What's the correct term for a waitress in the Middle Ages?
How to translate “Me doing X” like in online posts?
Why does Kathryn say this in 12 Monkeys?
Can an Eldritch Knight use Action Surge and thus Arcane Charge even when surprised?
How can drunken, homicidal elves successfully conduct a wild hunt?
Efficient integer floor function in C++
How can I get to the third table with an association?
accepts_nested_attributes_for child association validation failingHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How can a record belong_to a single user, but also have multiple “secondary” users?Creating Join Tables for has_many & belongs_to AssociationsRails 3 has_many :through is only adding id from on side of the relationshipHowto use callbacks in a has_many through association?how to permit an array with strong parametersHow find record with conditions for joined associationsjoins from belongs_to where query not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
A process has a Request
, then after approval, an Order
is created. At last, the customer gets a PaymentRequest
for the orders he made.
In the Request
, there is a project_id
, so in request model
:
belongs_to :project
The Order model
is connected to a Request
:
belongs_to :request
And every PaymentRequest
:
has_many :orders
What should I do in the PaymentRequest
model and other models so I would be able to get the project
from Request
?
So I would like to do something like:
PaymentRequest.where("requests.project_id = ?").joins(???)
ruby-on-rails
add a comment |
A process has a Request
, then after approval, an Order
is created. At last, the customer gets a PaymentRequest
for the orders he made.
In the Request
, there is a project_id
, so in request model
:
belongs_to :project
The Order model
is connected to a Request
:
belongs_to :request
And every PaymentRequest
:
has_many :orders
What should I do in the PaymentRequest
model and other models so I would be able to get the project
from Request
?
So I would like to do something like:
PaymentRequest.where("requests.project_id = ?").joins(???)
ruby-on-rails
add a comment |
A process has a Request
, then after approval, an Order
is created. At last, the customer gets a PaymentRequest
for the orders he made.
In the Request
, there is a project_id
, so in request model
:
belongs_to :project
The Order model
is connected to a Request
:
belongs_to :request
And every PaymentRequest
:
has_many :orders
What should I do in the PaymentRequest
model and other models so I would be able to get the project
from Request
?
So I would like to do something like:
PaymentRequest.where("requests.project_id = ?").joins(???)
ruby-on-rails
A process has a Request
, then after approval, an Order
is created. At last, the customer gets a PaymentRequest
for the orders he made.
In the Request
, there is a project_id
, so in request model
:
belongs_to :project
The Order model
is connected to a Request
:
belongs_to :request
And every PaymentRequest
:
has_many :orders
What should I do in the PaymentRequest
model and other models so I would be able to get the project
from Request
?
So I would like to do something like:
PaymentRequest.where("requests.project_id = ?").joins(???)
ruby-on-rails
ruby-on-rails
edited Mar 24 at 15:34
Noam B.
asked Mar 24 at 15:27
Noam B.Noam B.
1,17941326
1,17941326
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
PaymentRequest.joins(orders: :request).where("requests.project_id = ?", some_id)
or as suggested by Frederik:
PaymentRequest.joins(orders: :request).where(requests: project_id: some_id )
2
or maybe even.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
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%2f55325366%2fhow-can-i-get-to-the-third-table-with-an-association%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
PaymentRequest.joins(orders: :request).where("requests.project_id = ?", some_id)
or as suggested by Frederik:
PaymentRequest.joins(orders: :request).where(requests: project_id: some_id )
2
or maybe even.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
add a comment |
PaymentRequest.joins(orders: :request).where("requests.project_id = ?", some_id)
or as suggested by Frederik:
PaymentRequest.joins(orders: :request).where(requests: project_id: some_id )
2
or maybe even.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
add a comment |
PaymentRequest.joins(orders: :request).where("requests.project_id = ?", some_id)
or as suggested by Frederik:
PaymentRequest.joins(orders: :request).where(requests: project_id: some_id )
PaymentRequest.joins(orders: :request).where("requests.project_id = ?", some_id)
or as suggested by Frederik:
PaymentRequest.joins(orders: :request).where(requests: project_id: some_id )
edited Mar 24 at 15:58
answered Mar 24 at 15:48
Sajad RastegarSajad Rastegar
86221426
86221426
2
or maybe even.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
add a comment |
2
or maybe even.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
2
2
or maybe even
.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
or maybe even
.where(requests: project_id: some_id )
– Frederik Spang
Mar 24 at 15:53
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%2f55325366%2fhow-can-i-get-to-the-third-table-with-an-association%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