[FLOW3-general] inheritance and repositories
Mathis Hoffmann
mathis at hoffpost.de
Wed Apr 10 00:11:43 CEST 2013
Hi!
I've got one more question concerning inheritance in FLOW. Setup is as
it was before: One abstract Customer class that has two concrete child
classes, BusinessCustomer and PrivateCustomer. The Customer class has a
@ORM\InheritanceType("JOINED") annotation and I do have a
CustomerRepository that enables me to access, update and delete objects
of both type, Business- and PrivateCustomer[s]. So far everything works
well. I have created a CustomerController that is able to list all
customers. Now I want to implement an update-method in this controller.
I tried to write it using the following signature:
public function updateAction(HdM\Accounting\Domain\Model\Customer
$customer) {}
That ends up in an error that tells me that the updateAction requires a
parameter of type HdM\Accounting\Domain\Model\Customer but
HdM\Accounting\Domain\Model\Business(or Private)Customer has been given.
I hoped that FLOW would automatically upcast to it's parent class but it
doesn't. So far the only working solution I found is to write two
update-, create- and delete-methods, that require the concrete types,
which ends up in a lot of stupid copy/paste-work (6 more methods +
corresponding template files). I think there should be a smarter
solution but until now I have not been able to find it. I would be
really content if someone had a good solution for that.
Yours
Mathis
Am 08.04.2013 12:02, schrieb Mathis Hoffmann:
> Hey Steffen,
>
> thank you for your help. That works!!
>
> Yours
> Mathis
>
> Am 05.04.2013 23:41, schrieb Steffen Wickham:
>> Hey Mathis,
>>
>> I'm sorry, I assumed you already tagged your base class correctly. My
>> mistake, sorry!
>>
>> You have to add some annotations for your base class (AbstractAssignment
>> for me), so Doctrine/DBAL can create the right scheme. That's how I
>> annotate my base class:
>>
>> <?php
>> namespace AFSVN\Basic\Domain\Model;
>>
>> use Doctrine\ORM\Mapping as ORM;
>> use TYPO3\Flow\Annotations as Flow;
>>
>> /**
>> * @Flow\Entity
>> * @ORM\InheritanceType("JOINED")
>> */
>> abstract class AbstractAssignment {
>> ... (all shared values goes here) ...
>> }
>> ?>
>>
>>
>> So Doctrine creates a afsvn_basic_domain_model_abstractassignment table
>> with your shared values and a column "dtype", which holds a string
>> representation of you derived class, e.g. afsvn_basic_refereeassignment.
>> In the "afsvn_basic_domain_model_refereeassignment" table it use the
>> same identifier as the abstract table and holds only the
>> refereeassignment specific data. When you try to access an object by the
>> created repository, doctrine joins all data correctly, whether which
>> concrete class has been fetched.
>>
>> Yours
>> Steffen
>>
>>
>> Am 05.04.2013 23:30, schrieb Mathis Hoffmann:
>>> Hey Steffen,
>>>
>>> thank you for your quick reply!
>>>
>>> I just tried out your solution but it doesn't work for me. Did you
>>> maybe mark your AbstractAssignment as an entity? Marking Customer as
>>> an entity would not make sense for me because Doctrine would create a
>>> table that will never be filled with any values (because Customer is
>>> an abstract class)..
>>>
>>> Yours
>>> Mathis
>>>
>>> ---
>>> Mathis Hoffmann
>>> Tilsiter Straße 14
>>> 70374 Stuttgart
>>>
>>> Telefon: 0711 / 933 018 87
>>> Mobil: 0176 235 747 41
>>> E-Mail: mathis at hoffpost.de
>>>
>>> Am 05.04.2013 22:05, schrieb Steffen Wickham:
>>>> Hi Mathis,
>>>>
>>>> /**
>>>> * Repository for parties
>>>> *
>>>> * @Flow\Scope("singleton")
>>>> */
>>>> class AssignmentRepository extends
>>>> \TYPO3\Flow\Persistence\Repository {
>>>> const ENTITY_CLASSNAME =
>>>> 'AFSVN\Basic\Domain\Model\AbstractAssignment';
>>>> }
>>>> ?>
>>>> it's a really simple solution! I will post my repository but some
>>>> explanation first:
>>>>
>>>> I'd created two concrete classes called "RefereeAssignment" and
>>>> "ClubAssignment" which are derived from the same base class
>>>> "AbstractAssignment". All data can be accessed by the
>>>> "AssignmentRepository" which only consists of the following code:
>>>>
>>>> <?php
>>>> namespace AFSVN\Basic\Domain\Repository;
>>>> use TYPO3\Flow\Annotations as Flow;
>>>>
>>>> /**
>>>> * Repository for parties
>>>> *
>>>> * @Flow\Scope("singleton")
>>>> */
>>>> class AssignmentRepository extends
>>>> \TYPO3\Flow\Persistence\Repository {
>>>> const ENTITY_CLASSNAME =
>>>> 'AFSVN\Basic\Domain\Model\AbstractAssignment';
>>>> }
>>>> ?>
>>>>
>>>>
>>>> So you only have to set the base class as entity for the Repository
>>>> manually, otherwise Flow will determine the type itself.
>>>>
>>>> Yours
>>>> Steffen
>>>>
>>>>
>>>>
>>>> Am 05.04.2013 21:51, schrieb Mathis Hoffmann:
>>>>> Hi!
>>>>>
>>>>> I have some trouble implementing inheritance in my FLOW-app. The
>>>>> situation is as follows: I have an abstract superclass Customer with
>>>>> two subclasses BusinessCustomer and PrivateCustomer. Inheritance
>>>>> itself is working as it should. What I want to achieve now is that I
>>>>> have a CustomerRepository which enables me to list all Customers.
>>>>> Creating such a repository and a corresponding actioncontroller ends
>>>>> up in "No class schema found for
>>>>> "HdM\Accounting\Domain\Model\Customer"". Does anyone have a solution
>>>>> how that could work?
>>>>>
>>>>> Thank's in advance!
>>>>> Mathis Hoffmann
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> FLOW3-general mailing list
>>>>> FLOW3-general at lists.typo3.org
>>>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
>>>> _______________________________________________
>>>> FLOW3-general mailing list
>>>> FLOW3-general at lists.typo3.org
>>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
>>>
>>>
>>> _______________________________________________
>>> FLOW3-general mailing list
>>> FLOW3-general at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
>> _______________________________________________
>> FLOW3-general mailing list
>> FLOW3-general at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
>
>
>
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
More information about the FLOW3-general
mailing list