On 23 April 2015 at 04:47, Padmahas Bn <[email protected]> wrote: >> >Member.where(status: "active") >> >will give you the members, then you can use each to get >> > member.member_code >> > Hello Colin thank you very much. I was able to access member and loan table > from recovery model. > In rails guides i'm not able to find how to pass a variable to where clause. > > eg: I have retrieved the member_code of all members whose status is > 1(active) and extracted member_code like this > > @member = Member.where(record_status: "1")
That should be @members as it is plural > @member.each do |member| > tmember_code = member.member_code > > Now I want to pass tmember_code to where clause to perform some operation on > LoanTable. Is this the correct way? > > @loan = LoanTable.where(:memberCode => tmember_code, :loanType => "1") Best to stick to rails naming conventions, so it should be loan_type. Assuming that member has_many loans then this would be @loans = member.loans.where( loan_type: "1") If for some reason there is no such association (which seems very unlikely) then section 2.2 of http://guides.rubyonrails.org/active_record_querying.html is probably the way to go. But as I said in an earlier mail the fact that you have member_code in multiple tables is almost certainly an indication that your database design is poor. You should be using relationships instead. It will make your life much easier. Colin > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/460db5c7-6d46-4ba4-b713-a0a3a572d5bd%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuCEG1qJjXNpbf0tFWCLKMnWNrLhwv1X1YjbzeO2Lvd8A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

