ruby on rails - Rails3 help with joins scope -


There is a simple order - item app no ​​carriage need help with scoops connected to my report.

Item polymorphic ( related_to: item qualified,: polynomial => true ) with products, services and policies. The policy is related to the seller.

The goal is how much the seller was selling, but still be able to use the scope for the commands given below.

Scope in my order model

  scope: closed_tode, lambda {where ("closed date and stop_data> gt; and close_data  gt; and closed_data   

Something like this - Guess in the order model?

  Radius: with_policies, joins (: items).   

And the last result is by the seller being able to group and get the amount sold.

  & lt;% V in the @ order.closed_today.php_policies Group ("itemable.endor_id")%> & Lt;% = v.somehow_get_to.vendor.name% & gt; Sales: & lt;% = v.somehow_get_to.collect.sum (and: value)%>   

The price is the item field that assumes how much it has been sold for that item.

I would like to know that you can not group as the group shown above, so any sign on how to do this is that would be great to avoid adding vendor_id in my table of items .


UPDATE

This is a better way of ensuring that what I am doing is added to the seller for items made my life easier.

In my item model

  area: in_orders_with, lambda {| Order, type Where ('item qualify_ type IS?', Type) .zom (: order) & amp; Order}   

In my opinion (since @ order.closed_tude has actually passed from any other view.)

  <% orders = @ Orders.closed_today & gt%; & Lt; P & gt; & Lt;% @ ITEMS = item. In_ country_देश (order, "policy")%> & Lt;% if !@items.blank? & Gt%; & Lt;% @ items.group_by {| O | | O.vendor} .each do | Vendor, item | & Gt%; & Lt;% = seller.name% & gt; & Lt; Br / & gt; Volume sold out: & lt;% = items.count% & gt; Dollar Sell:    

  & lt;% @ orders.closed_today.with_policies.group_by {| O | O.itemable.vendor} .each Do | Seller, order | & Gt%; & Lt;% = seller.name% & gt; Saw: & lt;% = orders.sum (& amp;: Price)% & gt; & Lt;% end% & gt;    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -