At the moment, when I print say an invoice, I access
@order.customer.address.
Now I need to enhance the app to introduce the ability to map in
customer_detail from a new CustomerDetail model if one exists for that
order. But I want to avoid any changes to the existing code base
I have created TelephoneOrder < Order which carries all the new stuff
for Orders so as to minimise changes to existing stuff…
Now Rails is clever because when I find Order, it knows if
type=‘TelephoneOrder’ and instantiates as TelephoneOrder class.
I am thinking therefore that perhaps I can do something in
TelephoneOrder to ‘intercept’ @order.customer, and
@order.customer.address etc.
I have tried def address in TelephoneOrder and this does indeed
override the normal customer method only if the order is type
TelephoneOrder - Great so far!
This is where I am stuck. For a Telephone Order, I should now be able
to do something to replace the normal fields from Customer with the
fields from CustomerDetail.
My first thought was simply to use the customer object for that order
but change the fields as required before returning it. This ought to
fix all of the display occurrences, but would be dangerous in case the
customer gets saved somewhere, the fields will get overwritten.
So my question is - is there a way that I can get the customer object,
but return an inherited object, or something, which would effectively
be read only?
Tonypm