On 23 March 2010 02:15, Craig White <[email protected]> wrote:
> On Tue, 2010-03-23 at 03:02 +0100, Tony Tony wrote:
>> Craig White wrote:
>>
>> > I would have a table called pricing and have a column that had the
>> > customer_id and thus you might have 2 (or more) prices for an item but
>> > only one for a specific customer or default to the one that is not tied
>> > to a specific customer.
>>
>> Hi Craig!
>>
>> I don't think this would work as there are quite a number of clients
>> (over 25) who currently have a different price per product. In the
>> future there might be additional clients with custom pricing depending
>> on how much volume they push.
>>
>> If I were to implement your suggestion I would have to have 25+ fields
>> (pricing_1, pricing_2, pricing_3, etc.) which I don't think is the
>> correct approach for this. Did I misunderstand your suggestion?
> ----
> yes, you misunderstood... sorry if I wasn't clear enough. Something like
> this, definitely not tested and perhaps you can get it down to a single
> query.
>
> Class Pricing
> has_one :customer
> belongs_to :item

Should that be belongs_to: customer rather than has_one, along with
customer has_many pricings, and item has_many pricings?
I would have used class Price rather then Pricings but that is a
matter of personal preference.

Colin

>
> id
> price
> customer_id

You will need an item_id also

>
> def self.item_price(item, customer)
>  if Price.find(:first, :conditions => ["item_id = ? AND customer_id
> = ?", item, customer']) then
>    return Price.find(:first, :conditions => ["item_id = ? AND
> customer_id = ?", item, customer']).price
>  else
>    return Price.find(:first, :conditions => ["item_id = ? AND
> customer_id = NULL", item]).price
>  end
> end

This could be done as a named scope which might make for a neater solution.

Colin

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to