Let's say I have the following:
Product < AR
Memberships < Product
I know that the product with id 10 has its type column set to
"Membership", but still I'd like to treat it as a regular product.
So if I do: Product.find(10), Rails returns a Membership object.
Is it possible to tell rails to not care about STI and to simply return
a Product object?
Regards,
--
Posted via http://www.ruby-forum.com/.
But it *is* a Membership object... ?:-/
But if you *have* to have it as a Product for some reason, you can use
the ActiveRecord::Base "becomes" method:
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002334
#becomes is exactly what I was looking for, I didn't know about this
method and it's not featured in AWDWR 3rd Ed.
Thanks!
Makes sense.
> #becomes is exactly what I was looking for, I didn't know about this
> method and it's not featured in AWDWR 3rd Ed.
Kewl. Glad to help.
AWDWR is a good book - but it's not all-encompassing... You need to
get familiar with navigating the Ruby and Rails API documentation to
find the rest of the cool stuff :-)