See my comment inline.

----- Original Message ----- 
From: "Mattias Campe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 9:37 PM
Subject: [castor-dev] FAQ: question about "Different cardinalities of relationship"


> Hi,
> 
> as I need a similar example as on
> http://castor.exolab.org/castor-one.html#Different-cardinalities-of-relationship 
> 
> (my example would be that a customer could also belong to more then 1
> department),  I read this faq, but I don't understand it quiet well :(.
> 
> The Employee table has "id", "name" and "salary". There's is a mapping
> for "id" and "salary", but for "name" there seems only to be:
> 
> <field>
>    <sql many-table="employee_department" many-key="e_id" name="d_id"/>
> </field>

The mapping for name is missing. 

The above mapping line tells castor that identity 'id' (see class element) is
referenced by many-key 'e_id' of many-table 'employee_department' with 
this table having another reference column 'd_id'.

> 
> Could this be a mistake, I mean, the mapping for "name" is probably left 
> out? I also can't figure out how Castor knows where to get "d_id"?
> 
> If this example would be completed, how could it look like? For the 
> object model, could it be:
> Employee{
>    get/setID();
>    get/setName();
>    get/SetSalary();
>    joinDepartment(); //-> for my example, an employee can...
>    leaveDepartment(); //   ...belong to more then 1 department
>    getDepartments();

For relations castor searches for the following methods:

void addDepartments(Department dept)
void setDepartments(Vector depts)
Vector getDepartments()

The default naming for methods can be changed by declaring different methode
names in the field element of the mapping file:

get-methode="getAllDepartments"
set-methode="setAllDepartments"
add-methode="addDepartment"

> }
> 
> Department {
>    get/setID();
>    get/setName();
>    get/setComment();
>    addEmployee();
>    removeEmployee();
>    getEmployees();
> }
> 
> But then I get stuck with providing a correct mapping, I'm hoping sb. 
> could help me with this one. The bidirectional mapping went smooth, but 
> this one is a bit more difficult :(.
> 
> greetings,
> Mattias Campe
> 


Have you had a look a the example shiped with castor source archiv. The
important files for you are in directories 'src/examples/jdo' and 
'src/examples/myapp'. See Product and Categorie for a many-many
relationship example.

Regards
Ralf

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to