[TYPO3-mvc] DataMapper: relations with custom constraint?
Lienhart Woitok
Lienhart.Woitok at netlogix.de
Tue Jan 26 15:45:56 CET 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi list,
please consider the following situation:
We have products which have customer specific prices. This means, for each product and each customer a price is defined. So the domain model looks (simplified) like this:
+------------+
| Product |
+------------+ +-----------+
| prices |- - - - - >| Price |
+------------+ +-----------+ +--------------+
| customer |- - - - - >| FrontendUser |
+-----------+ +--------------+
Product is aggregate root. Each product can have many prices, each price belongs to exactly one product. Each price is associated with exactly one customer.
Now I have a ProductRepository. I do a findAll() on it and get all my products. No problem so far. The prices property of each product contains the associated prices as expected. (But it is real slow with more than 1000 products and more than 800000 prices.)
But I don't want all prices, just those associated with the logged in FrontendUser. And now I'm a bit lost. I've dug into the code of extbase and found the Tx_Extbase_Persistence_Mapper_DataMapper class, which fetches related records. But I couldn't figure out how to add a custom constraint on the created query. I guess it is not possible with the current code.
I'm willing to implement this and provide a patch, but I'm not sure about what way would be best.
A possible approach might be to give the Repository a way to pass on constraints to the DataMapper, but this probably gets awkward if nesting becomes deeper.
Another thought was a custom ObjectStorage or LazyLoadingProxy, but this is not flexible enough, as for example in Backend I have no FrontendUser and in my use case wouldn't want a constraint on a FrontendUser but edit prices for all users.
So it might be a good idea to configure this in persistence settings, like some class a query should ask for special constraints?
A few hints or pointers about how this could or should be done would be very much appreciated. Maybe there even exists a simple solution I didn't think of yet, who knows?
Kind regards,
Lienhart Woitok
TYPO3 Entwickler
Telefon: +49 (911) 539909 - 0
E-Mail: Lienhart.Woitok at netlogix.de
- --
netlogix GmbH & Co. KG
Systemhaus | Trainingscenter | Medienagentur
Andernacher Straße 53 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: mailto:info at netlogix.de | Internet: http://www.netlogix.de/
netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt
-----BEGIN PGP SIGNATURE-----
Version: PGP Universal 2.12.0 (Build 1035)
Charset: Windows-1252
wpUDBQFLXwAnWevMF2ftbKMBCDCcA/9EvJZYjGCyGOrHCjpoIgefv73UyGUiV+qb
M12HY7cHrSjQV1B6cWbdGsfWWOqB+n91U/JEQlVsBE842GlId9RGemBNZjCR3CPG
DjrR+7OG0fgKwCu0JnyOVVbXckMD8CoLP05rDXM9YDV7JMU1KXybyk6sFFF1zyZC
Y95ggYHJew==
=pBYg
-----END PGP SIGNATURE-----
More information about the TYPO3-project-typo3v4mvc
mailing list