Hello,
I had a question about the usage of CCV5 with 2 models.
Model 1 is the main model: Project
This table is to define a project. The associated primary key of this model is project_id.
Model 2: Team member.
This table is to define the team members belongs to the project. The primary key of this model is "id".
So in Model 1 (Project), I list the project where I am the owner, with the condition below:
In the model 2 (Team member), I had to associate the team members to the project. The cardinality is 1 project with several team members.
As team members belongs to the project, if I delete or save the project, I delete or save all the records of the team members where the team members belongs to the project.
So Associative Save is "Yes".
and Associative Delete is "Yes".
The Foreign Key is "project_id", if I referred to the comment for this field (The foreign key field used in the relation, either in the main model or in this model, this depends on the relation type.)
The primary key of this model is "id", if I referred to the comment for this field (The primary key for this model, you should only fill this if your table does NOT have a primary key, the field name here will be used for some operations.)
Question:
What is the relation then? (blank, hasone, belongsto, hasmany). The comment for the usage for this field is not clear to me.
the join type? (left, right)
and the Join conditions (Column project_id of Model 2 is the column project_id of Model 1). How to write this in CCV5 fields?
Thanks
Bertrand
I had a question about the usage of CCV5 with 2 models.
Model 1 is the main model: Project
This table is to define a project. The associated primary key of this model is project_id.
Model 2: Team member.
This table is to define the team members belongs to the project. The primary key of this model is "id".
So in Model 1 (Project), I list the project where I am the owner, with the condition below:
<?php
$user = \JFactory::getUser();
return array('PT.user_id'=>$user->id);
?>
In the model 2 (Team member), I had to associate the team members to the project. The cardinality is 1 project with several team members.
As team members belongs to the project, if I delete or save the project, I delete or save all the records of the team members where the team members belongs to the project.
So Associative Save is "Yes".
and Associative Delete is "Yes".
The Foreign Key is "project_id", if I referred to the comment for this field (The foreign key field used in the relation, either in the main model or in this model, this depends on the relation type.)
The primary key of this model is "id", if I referred to the comment for this field (The primary key for this model, you should only fill this if your table does NOT have a primary key, the field name here will be used for some operations.)
Question:
What is the relation then? (blank, hasone, belongsto, hasmany). The comment for the usage for this field is not clear to me.
the join type? (left, right)
and the Join conditions (Column project_id of Model 2 is the column project_id of Model 1). How to write this in CCV5 fields?
Thanks
Bertrand
Hi bcouvin,
relation depends on which model is related to which, if its the "team member" to a "project" then its "belongsTo", if its the other way then its "hasMany".
The join type should be left empty most of the time, this setting is dropped in v6
Please ignore the join conditions if your tables have a primary key and no extra conditions are needed beside the default "foreign key = primary key" condition.
I suggest that you don't enable the associated delete/save before you are sure that everything is setup correct.
What are you trying to do exactly ? just listing the data ?
Best regards,
Max
relation depends on which model is related to which, if its the "team member" to a "project" then its "belongsTo", if its the other way then its "hasMany".
The join type should be left empty most of the time, this setting is dropped in v6
Please ignore the join conditions if your tables have a primary key and no extra conditions are needed beside the default "foreign key = primary key" condition.
I suggest that you don't enable the associated delete/save before you are sure that everything is setup correct.
What are you trying to do exactly ? just listing the data ?
Best regards,
Max
Hi Max,
Thanks for the explanation.
This sentence was not clear to me:
My main model is "Project". The model 2 is "Team Member".
The project has many TeamMembers. One row in the "Project" table. I may have several rows in "TeamMembers" table (Cardinality 1 project and N Team Members). So I has to fill "hasmany" or "belongsto" in the "TeamMember" tab?
If I understood, I have to fill "belongsto" the main model which is "Project". Is it correct?
Could you clarify this for me?
Thanks
Bertrand
Thanks for the explanation.
This sentence was not clear to me:
relation depends on which model is related to which, if its the "team member" to a "project" then its "belongsTo", if its the other way then its "hasMany".
My main model is "Project". The model 2 is "Team Member".
The project has many TeamMembers. One row in the "Project" table. I may have several rows in "TeamMembers" table (Cardinality 1 project and N Team Members). So I has to fill "hasmany" or "belongsto" in the "TeamMember" tab?
If I understood, I have to fill "belongsto" the main model which is "Project". Is it correct?
Could you clarify this for me?
Thanks
Bertrand
Hi Bertrand,
Since you main model is "Project" then you have to use "hasMany" under the "Team member" model.
Best regards,
Max
Since you main model is "Project" then you have to use "hasMany" under the "Team member" model.
Best regards,
Max
This topic is locked and no more replies can be posted.