[TYPO3-mvc] sub-models within the model table
Jochen Rau
jochen.rau at typoplanet.de
Mon Apr 19 11:27:51 CEST 2010
Hi Masi.
On 19.04.10 10:32, Martin Kutschker wrote:
> Martin Kutschker schrieb:
>> 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:
You made a clear statement of your intention, but I didn't read it
carefully ;-) But I did now.
> 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.
Your design to encapsulate the properties related to one another in a
separate object Address is the way I would do this, too. You can avoid
the duplication of code by having a general
Tx_MyExt_Domain_Model_Address holding all the getters and setters. And
empty classes Tx_MyExt_Domain_Model_ShippingAddress and
Tx_MyExt_Domain_Model_BillingAddress. Now, you might want to try the
configuration I have already posted ;-).
You don't have to create a new table (as you can reuse tt_address). BTW
I plan to publish reusable Generic Domain Models soon (Party, Person,
Organization, Address, ContactNumber etc.).
Hopefully I got the point here.
Regards
Jochen
More information about the TYPO3-project-typo3v4mvc
mailing list