Hello Collin,

Changed the naming according to conventions of rails. And yeah about
database, I haven't designed them with any relations yet.

On Thu, Apr 23, 2015 at 1:13 PM, Colin Law <clan...@gmail.com> wrote:

> On 23 April 2015 at 04:47, Padmahas Bn <padma...@gmail.com> 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 rubyonrails-talk+unsubscr...@googlegroups.com.
> > To post to this group, send email to rubyonrails-talk@googlegroups.com.
> > 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 rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> 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.
>

-- 
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 rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAC_h78LXR6A22D0q0j3a_d6HAP2_sQn3YvuiPh7kZXM8mDqxJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to