sql - rails named scope issues -


I have two designated scopes ... both of which work separately, but when combined do not work.

  Named_scope: Total,: Select => "As the COUNT (*) days, average (value) as the value, SUM (value) total" ,: group = & gt; : Parent_id name_scope: currency, lambda {| Code | {: Choose => Example:  

P>

  C = booking Total.currency ("EUR") Find_all_by_parent_id (63)  

The total designated scope works but the currency is not ...

  c = Booking.currency ("EUR"). Total.find_all_by_parent_id (63)  

Scope named design works, but not yoga ...

Any thoughts?

I think you have some problems.

  • Both scope "define value" and they define conflict, this will generate invalid SQL

  • One scope There is a group segment, but there is not an overall work on the non-classified feature in the second selection section, the result will be in the invalid SQL.

Instead of the complexity of your class, consider using a math feature on your booking model.

  Class Booking DIF currency (code = "USD") Price * CurrencyRate.get_rate (code), 1) End and  

You can do this now

Booking for ticket in booking = booking.otal_fin_all_by_parent_id (63) ends booking.currency ("EUR")

if you If you want to use a scope, then consider combining them. I know you probably do not want to designate nomination for each permutation, but I think there must be some changes. You can create a named_scope: currency_total

  named_scope: currency_total, lambda {| Code | {: Choose => "Value as the price (*), AVG (Price * # {(currency RA.GetTrot (" US Dollar ", (code =" USD "), 1))}) As the value, SUM (Value * # Get_rate ("USD", (code || = "USD"), 1))}) Total ",: group = & gt; : Parent_id}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -