[TYPO3-mvc] extbase: relations simple question
Dmitri Pusarev
dimaip at gmail.com
Wed Feb 17 20:15:48 CET 2010
Hey Christine!
Christine Gerpheide wrote:
> In kickstarter you only need to add "projects" inside of the Client object
> (and then connect it with the little wire to the Project model). In the
> database, this will create a "client" uid field inside of the project table.
> More importantly, though, it will create the property "projects" inside of
> the Client model class (along with getProjects()/setProjects()), which as I
> said before I think is the appropriate way of retrieving projects for a
> client.
>
> Does this answer your question?
Well, no.
What you have wrote is obvious and I do so already, but what if I want
to find out which client a particular project belongs to?
This?:
$client = $this->clientRepository->findByProject($project);
Or do I have to define two relations for each side, to be able to call this:
$client = $project->getClient();
I looked up the blog_example, and there a relation between Blog and Post
is defined both ways. So if I do the same in kickstarter it would look
ugly having two wires for pair of objects.
What I have decided yet, is to rely solely on semantics, examples:
client-project - I created both relations.
client-contact - One way, the $client->contacts;
project-subproject - Both ways;
service-servicetype - One way again, $service->servicetype; So if I want
to find all services of given type I use the
$serviceRepository->findByServicetype($servicetype);
So if I can say that B is a property of A, then I create a relation that
way, if not then I just do $aRepository->findByB($b);
Did I grasp the point correctly, or do I need to think of it again?
Thanks!
Cheers,
Dmitri.
>
> 2010/2/15 Dmitri Pusarev <dimaip at gmail.com>
>
>> Thanks Thomas and Christine!
>>
>>
>> Thomas "Thasmo" Deinhamer wrote:
>>
>>> You can of course use both ways, if you like:
>>>
>>> $projects = $client->getProjects();
>>> $client = $project->getClient();
>>>
>> Yeah, but to use it both ways I need to create relationships in both ways,
>> right? Which is both a) and b), answering my first question.
>>
>> a)Client has a relation projects with Project, 0..*(fk).
>> b)Project has a relation client with Client, 0..1.
>>
>> It looks very weird in the kickstarter when creating relations both ways.
>> The only alternative to this is crearing only "a)Client has a relation
>> projects with Project, 0..*(fk)." Then this is what works:
>> $projects = $client->getProjects();
>> $client = $this->clientRepository->findByProject($project);
>> Which is again kind of ugly.
>>
>> Plus in the kickstarter when I create both relations, it duplicates the
>> client field in ext_tables.sql and in tca.php:
>> "client int(11) unsigned DEFAULT '0'
>> client int(11) unsigned DEFAULT '0'"
>> Which makes me doubt this is the correct way of doing things.
>>
>> So once again, please answer my first question, is it really the best
>> approach to create two relations for each pair of objects? It feels right,
>> but in kickstarter it just looks messy... For example in IBM rational
>> modeler things are much more simple: you just define on every edge of a link
>> its name and multitude. In this example it would look like: Client(projects
>> 0..1)<---->Project(0..* client)
>>
>>
>>
>>
>>> Greatings,
>>> Thomas
>>>
>>> Am 15.02.2010 19:49, schrieb Dmitri Pusarev:
>>>
>>>> OK, I think I can make my question more specific:
>>>> a) $projects = $client->getProjects();
>>>> b) $this->projectRepository->findByClient($client);
>>>> Which is better to get all projects for given client, a) or b)?
>>>>
>>>>
>>>> Dmitri Pusarev wrote:
>>>>
>>>>> Hey!
>>>>> In my model I have a Client and a Project. Relations which pop into my
>>>>> mind from the business domain:
>>>>> a)Client has a relation projects with Project, 0..*(fk).
>>>>> b)Project has a relation client with Client, 0..1.
>>>>> Should I create both a) and b)? Or just a) is enough?
>>>>>
>>>>> In the database language(which I more used to), I would just create a
>>>>> field 'client' in the table 'Projects'.
>>>>>
>>>>> Sorry, I'm still learning!
>>>>>
>>>>> Cheers,
>>>>> Dmitri.
>>>>>
>>>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>
More information about the TYPO3-project-typo3v4mvc
mailing list