On Tue, 2010-03-23 at 03:28 +0100, Tony Tony wrote:
> Craig White wrote:
> > 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
> > 
> > id
> > price
> > customer_id
> > 
> > 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
> > 
> > Craig
> > 
> > 
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> 
> 
> AH! Okay - I think I got it.
> 
> So you would just remove the price field from the item table altogether 
> and just put it in its own table.
> 
> Any tips or resources on the best way on how to do this? Still a bit of 
> a rails newbie. Thanks!
----
I would not have a 'price' column in my items table at all. I might
consider having a customer '1' that was say 'retail' and customer '2'
that was say 'wholesale' and maybe even customer '3' that was Internet
so I could have all sorts of different pricing levels for each item in
addition to having customer specific pricing.

Thus you could define in the Pricing model, things like...

def self.default_price
  return Price.find(:first, 
    :conditions => ["item_id = ? AND customer_id = ?", item, 1]).price
end

etc.

Exploit the power of models

Craig



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
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