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;








0















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(???)









share|improve this question






























    0















    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(???)









    share|improve this question


























      0












      0








      0


      0






      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(???)









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 15:34







      Noam B.

















      asked Mar 24 at 15:27









      Noam B.Noam B.

      1,17941326




      1,17941326






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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 )





          share|improve this answer




















          • 2





            or maybe even .where(requests: project_id: some_id )

            – Frederik Spang
            Mar 24 at 15:53











          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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 )





          share|improve this answer




















          • 2





            or maybe even .where(requests: project_id: some_id )

            – Frederik Spang
            Mar 24 at 15:53















          1














          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 )





          share|improve this answer




















          • 2





            or maybe even .where(requests: project_id: some_id )

            – Frederik Spang
            Mar 24 at 15:53













          1












          1








          1







          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 )





          share|improve this answer















          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 )






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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












          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript