[TYPO3-mvc] sub-models within the model table
Martin Kutschker
masi-no at spam-typo3.org
Mon Apr 19 10:32:31 CEST 2010
Martin Kutschker schrieb:
> Hi!
>
> Let's assume we have a customer model. It has two addresses one for shipping and one for billing. We
> further assume that we don't need tha address on it's own (quite likely in a shop application) and
> so we don't want to create a separate address table.
>
> The table looks like this:
>
> id
> name
> shipping_address
> shipping_postcode
> shipping_city
> billing_address
> billing_postcode
> billing_city
>
> My idea is now to model those two addresses as models with the customer model rather then a bunch of
> unrelated properties of the customer. If the address sub-model is general enough it could be reused
> in any other model (and table).
I think I made myself not clear. There will only be one table "customer". And the customer model
looks like this:
class customer {
// @var string
var $name;
// @var Address_Model
var $shipping;
// @var Address_Model
var $billing;
}
Perhaps I should have written nested model instead of sub model.
The point is that you don't have to duplicate all those setters and getters and all the validation
code that comes with an address. OTOH you don't have to create a new table, so you avoid extra joins.
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list