Thursday, September 9, 2010

Re: [Rails] view on index pages data from custom SQL statements

On 9 September 2010 12:14, Daniel Morigan <daniel.morigan@gmail.com> wrote:
> I need to show on my index page in one of the collumns data that would
> be result of a SQL statment. Is there a universal way to do it? In my
> current case I have table A and B, A has many B, B belongs to A. In my
> A's index page I need to have data that would be the result of such
> SQL statement:
> select count(*) from B where A_id=x and B.number > y

Don't use an sql statement, use the ActiveRecord API. Assuming that
you have an A object, an_a, then something like
the_count = an_a.bs.find( :all, :conditions => { :number => x } ).count
should do the trick (untested).

Colin

> The result of this statement is a number and I need to show this
> number in one collumn.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate