ManyToMany mappings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

ManyToMany mappings

Nathaniel Rowe
I'm working on a project for school that involves building a course
management system, and I need to use ManyToMany mappings for a few
classes (for now, just the Student and Course classes). I haven't been
able to find any documentation on the mappings which can give me a
good example of how to implement a ManyToMany mapping, which I need
since each Course has multiple students, and each student has multiple
courses. Any help with setting this up is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Alan Knight
Basically, put a many to many mapping in your descriptor and define a
link table for the relationship which has foreign key constraints to
both tables. It should figure it out automatically.

On Mar 18, 9:44 am, Rowe <[hidden email]> wrote:
> I'm working on a project for school that involves building a course
> management system, and I need to use ManyToMany mappings for a few
> classes (for now, just the Student and Course classes). I haven't been
> able to find any documentation on the mappings which can give me a
> good example of how to implement a ManyToMany mapping, which I need
> since each Course has multiple students, and each student has multiple
> courses. Any help with setting this up is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Nathaniel Rowe
descriptorForProffessor: aDescriptor
        (aDescriptor newMapping: ManyToManyMapping)
                attributeName: #id;
                referenceClass: Section.


descriptorForSection: aDescriptor
        "(aDescriptor newMapping: ManyToManyMapping)
                attributeName: #id;
                referenceClass: Proffessor."

So I've added those descriptors, and it tells me "Error: Cannot
calculate the join automatically, not enough information.Error: Cannot
calculate the join automatically, not enough information." I assume
that's where the linking table comes in, but I must not be doing the
table correctly. Do I create a brand new table, and put in something
like the following?

section_id := aTable createFieldNamed: 'sections' type: platform
integer.
aTable addForeignKeyFrom: section_id to: ((self tableNamed:
'sections') fieldNamed: 'id').
proffessor_id := aTable createFieldNamed: 'profs' type: platform
integer.
aTable addForeignKeyFrom: proffessor_id to: ((self tableNamed:
'proffessors') fieldNamed: 'id').

Being pretty much brand new to this system, I'm about as lost as
possible right now.

On Mar 18, 10:09 am, "alan.knight" <[hidden email]> wrote:
> Basically, put a many to many mapping in your descriptor and define a
> link table for the relationship which has foreign key constraints to
> both tables. It should figure it out automatically.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Alan Knight
Yes, you do need to define a table that has the foreign keys, pretty
much as you've written it. I think your issue is with the basic
mappings. You've got an attribute in proffessor named "id", but you
want it to be a collection of sessions. Normally "id" would just be
direct mapping to your own primary key. So you want to define a
mapping named something else, like "sections". You'll need a variable
defined in the class for that, obviously. And in fact, if you do name
it "sections", then you don't even need to create the mapping, it'll
assume that you want it to be a collection of Section objects. And if
the tables indicate that the way to get from professor to section is
via the link table, it'll do that too, and only complain if there's
more than one way (or if there are zero ways).

So if you did want to write the mapping out, it'd be something like
 descriptorForProffessor: aDescriptor
         (aDescriptor newMapping: ManyToManyMapping)
                 attributeName: #sections;
                 referenceClass: Section.



On Mar 18, 10:49 am, Rowe <[hidden email]> wrote:

> descriptorForProffessor: aDescriptor
>         (aDescriptor newMapping: ManyToManyMapping)
>                 attributeName: #id;
>                 referenceClass: Section.
>
> descriptorForSection: aDescriptor
>         "(aDescriptor newMapping: ManyToManyMapping)
>                 attributeName: #id;
>                 referenceClass: Proffessor."
>
> So I've added those descriptors, and it tells me "Error: Cannot
> calculate the join automatically, not enough information.Error: Cannot
> calculate the join automatically, not enough information." I assume
> that's where the linking table comes in, but I must not be doing the
> table correctly. Do I create a brand new table, and put in something
> like the following?
>
> section_id := aTable createFieldNamed: 'sections' type: platform
> integer.
> aTable addForeignKeyFrom: section_id to: ((self tableNamed:
> 'sections') fieldNamed: 'id').
> proffessor_id := aTable createFieldNamed: 'profs' type: platform
> integer.
> aTable addForeignKeyFrom: proffessor_id to: ((self tableNamed:
> 'proffessors') fieldNamed: 'id').
>
> Being pretty much brand new to this system, I'm about as lost as
> possible right now.
>
> On Mar 18, 10:09 am, "alan.knight" <[hidden email]> wrote:> Basically, put a many to many mapping in your descriptor and define a
> > link table for the relationship which has foreign key constraints to
> > both tables. It should figure it out automatically.
>
>

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

giorgiof
In reply to this post by Nathaniel Rowe
Hi, 

There is a possible different solution, and this is the one that brings to consider the many to many relationship as a real class that has meanings in the modeling of the domain, so you end up with something as CourseForStudent, This brings 2 one to many relationship between Student - CourseForStudent and  Course -CourseForStudent, and eliminate the many to many. And also add the possibility to give behavior and state to the new class (for example it can holds how many hours the student spent on the course, etc.) .
I know this is not an answer for your question (Alan answered to this) but it is a different perspective that can be helpful.  BTW I never used on my life many to many but always a class representing the relationship, and usually this brought advantages to the application.
I'm interested to know if other have different opinion.

ciao

Giorgio 


On Thu, Mar 18, 2010 at 2:44 PM, Rowe <[hidden email]> wrote:
I'm working on a project for school that involves building a course
management system, and I need to use ManyToMany mappings for a few
classes (for now, just the Student and Course classes). I haven't been
able to find any documentation on the mappings which can give me a
good example of how to implement a ManyToMany mapping, which I need
since each Course has multiple students, and each student has multiple
courses. Any help with setting this up is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.


--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Nathaniel Rowe
So, I'm trying an intermediary class like giorgia suggested. For the life of me, I haven't been able to get the many to many mappings working, so it seemed prudent to just try and move forward with the project. Thanks for the help guys, it's been quite valuable, even though I wasn't able to get it.

On Fri, Mar 19, 2010 at 8:08 AM, giorgio ferraris <[hidden email]> wrote:
Hi, 

There is a possible different solution, and this is the one that brings to consider the many to many relationship as a real class that has meanings in the modeling of the domain, so you end up with something as CourseForStudent, This brings 2 one to many relationship between Student - CourseForStudent and  Course -CourseForStudent, and eliminate the many to many. And also add the possibility to give behavior and state to the new class (for example it can holds how many hours the student spent on the course, etc.) .
I know this is not an answer for your question (Alan answered to this) but it is a different perspective that can be helpful.  BTW I never used on my life many to many but always a class representing the relationship, and usually this brought advantages to the application.
I'm interested to know if other have different opinion.

ciao

Giorgio 


On Thu, Mar 18, 2010 at 2:44 PM, Rowe <[hidden email]> wrote:
I'm working on a project for school that involves building a course
management system, and I need to use ManyToMany mappings for a few
classes (for now, just the Student and Course classes). I haven't been
able to find any documentation on the mappings which can give me a
good example of how to implement a ManyToMany mapping, which I need
since each Course has multiple students, and each student has multiple
courses. Any help with setting this up is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.


--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Alan Knight
That will work, and often makes sense in terms of the model. But it
also really shouldn't be difficult at all to get a many to many
mapping going. I'm posting this directly through google groups, and it
wasn't obvious how to attach something, so I've published something
called ManyToManyExample into the WebVelocity community repository.

It's extremely basic, and one of the class names is spelled wrong, but
it works. The thing that's tricky is in fact not the database but
maintaining the relationship in memory. I think the way the
scaffolding is working, if you add a professor to a section, it's just
going to add it directly to the collection on one side of the
relationship, but the corresponding collection on the professor's side
wouldn't be updated. So you'd need to customize the edit classes to do
that. But the database will write it if it's present on either side of
the relationship, and next time you read it it would be fine.

On Mar 20, 1:05 am, Nathaniel Rowe <[hidden email]> wrote:

> So, I'm trying an intermediary class like giorgia suggested. For the life of
> me, I haven't been able to get the many to many mappings working, so it
> seemed prudent to just try and move forward with the project. Thanks for the
> help guys, it's been quite valuable, even though I wasn't able to get it.
>
> On Fri, Mar 19, 2010 at 8:08 AM, giorgio ferraris <[hidden email]> wrote:
> > Hi,
>
> > There is a possible different solution, and this is the one that brings to
> > consider the many to many relationship as a real class that has meanings in
> > the modeling of the domain, so you end up with something as
> > CourseForStudent, This brings 2 one to many relationship between Student -
> > CourseForStudent and  Course -CourseForStudent, and eliminate the many to
> > many. And also add the possibility to give behavior and state to the new
> > class (for example it can holds how many hours the student spent on the
> > course, etc.) .
> > I know this is not an answer for your question (Alan answered to this) but
> > it is a different perspective that can be helpful.  BTW I never used on my
> > life many to many but always a class representing the relationship, and
> > usually this brought advantages to the application.
> > I'm interested to know if other have different opinion.
>
> > ciao
>
> > Giorgio
>
> > On Thu, Mar 18, 2010 at 2:44 PM, Rowe <[hidden email]> wrote:
>
> >> I'm working on a project for school that involves building a course
> >> management system, and I need to use ManyToMany mappings for a few
> >> classes (for now, just the Student and Course classes). I haven't been
> >> able to find any documentation on the mappings which can give me a
> >> good example of how to implement a ManyToMany mapping, which I need
> >> since each Course has multiple students, and each student has multiple
> >> courses. Any help with setting this up is greatly appreciated.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "WebVelocity" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> [hidden email]<webvelocity%[hidden email]>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/webvelocity?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "WebVelocity" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email]<webvelocity%[hidden email]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/webvelocity?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Nathaniel Rowe
Well, I have no idea what I was doing wrong, but I adapted the code you posted to my project, and it's working fine. I swear I had that exact same setup at one point, but I must have been missing one little thing, because it's working fine now. Thanks so much for the help.

On Sat, Mar 20, 2010 at 12:51 PM, alan.knight <[hidden email]> wrote:
That will work, and often makes sense in terms of the model. But it
also really shouldn't be difficult at all to get a many to many
mapping going. I'm posting this directly through google groups, and it
wasn't obvious how to attach something, so I've published something
called ManyToManyExample into the WebVelocity community repository.

It's extremely basic, and one of the class names is spelled wrong, but
it works. The thing that's tricky is in fact not the database but
maintaining the relationship in memory. I think the way the
scaffolding is working, if you add a professor to a section, it's just
going to add it directly to the collection on one side of the
relationship, but the corresponding collection on the professor's side
wouldn't be updated. So you'd need to customize the edit classes to do
that. But the database will write it if it's present on either side of
the relationship, and next time you read it it would be fine.

On Mar 20, 1:05 am, Nathaniel Rowe <[hidden email]> wrote:
> So, I'm trying an intermediary class like giorgia suggested. For the life of
> me, I haven't been able to get the many to many mappings working, so it
> seemed prudent to just try and move forward with the project. Thanks for the
> help guys, it's been quite valuable, even though I wasn't able to get it.
>
> On Fri, Mar 19, 2010 at 8:08 AM, giorgio ferraris <[hidden email]> wrote:
> > Hi,
>
> > There is a possible different solution, and this is the one that brings to
> > consider the many to many relationship as a real class that has meanings in
> > the modeling of the domain, so you end up with something as
> > CourseForStudent, This brings 2 one to many relationship between Student -
> > CourseForStudent and  Course -CourseForStudent, and eliminate the many to
> > many. And also add the possibility to give behavior and state to the new
> > class (for example it can holds how many hours the student spent on the
> > course, etc.) .
> > I know this is not an answer for your question (Alan answered to this) but
> > it is a different perspective that can be helpful.  BTW I never used on my
> > life many to many but always a class representing the relationship, and
> > usually this brought advantages to the application.
> > I'm interested to know if other have different opinion.
>
> > ciao
>
> > Giorgio
>
> > On Thu, Mar 18, 2010 at 2:44 PM, Rowe <[hidden email]> wrote:
>
> >> I'm working on a project for school that involves building a course
> >> management system, and I need to use ManyToMany mappings for a few
> >> classes (for now, just the Student and Course classes). I haven't been
> >> able to find any documentation on the mappings which can give me a
> >> good example of how to implement a ManyToMany mapping, which I need
> >> since each Course has multiple students, and each student has multiple
> >> courses. Any help with setting this up is greatly appreciated.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "WebVelocity" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> [hidden email]<[hidden email]>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/webvelocity?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "WebVelocity" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email]<[hidden email]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/webvelocity?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.


--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany mappings

Alan Knight
You're welcome. Glad to hear it's working for you now.

On Mar 20, 6:51 pm, Nathaniel Rowe <[hidden email]> wrote:

> Well, I have no idea what I was doing wrong, but I adapted the code you
> posted to my project, and it's working fine. I swear I had that exact same
> setup at one point, but I must have been missing one little thing, because
> it's working fine now. Thanks so much for the help.
>
> On Sat, Mar 20, 2010 at 12:51 PM, alan.knight <[hidden email]> wrote:
> > That will work, and often makes sense in terms of the model. But it
> > also really shouldn't be difficult at all to get a many to many
> > mapping going. I'm posting this directly through google groups, and it
> > wasn't obvious how to attach something, so I've published something
> > called ManyToManyExample into the WebVelocity community repository.
>
> > It's extremely basic, and one of the class names is spelled wrong, but
> > it works. The thing that's tricky is in fact not the database but
> > maintaining the relationship in memory. I think the way the
> > scaffolding is working, if you add a professor to a section, it's just
> > going to add it directly to the collection on one side of the
> > relationship, but the corresponding collection on the professor's side
> > wouldn't be updated. So you'd need to customize the edit classes to do
> > that. But the database will write it if it's present on either side of
> > the relationship, and next time you read it it would be fine.
>
> > On Mar 20, 1:05 am, Nathaniel Rowe <[hidden email]> wrote:
> > > So, I'm trying an intermediary class like giorgia suggested. For the life
> > of
> > > me, I haven't been able to get the many to many mappings working, so it
> > > seemed prudent to just try and move forward with the project. Thanks for
> > the
> > > help guys, it's been quite valuable, even though I wasn't able to get it.
>
> > > On Fri, Mar 19, 2010 at 8:08 AM, giorgio ferraris <
> > [hidden email]> wrote:
> > > > Hi,
>
> > > > There is a possible different solution, and this is the one that brings
> > to
> > > > consider the many to many relationship as a real class that has
> > meanings in
> > > > the modeling of the domain, so you end up with something as
> > > > CourseForStudent, This brings 2 one to many relationship between
> > Student -
> > > > CourseForStudent and  Course -CourseForStudent, and eliminate the many
> > to
> > > > many. And also add the possibility to give behavior and state to the
> > new
> > > > class (for example it can holds how many hours the student spent on the
> > > > course, etc.) .
> > > > I know this is not an answer for your question (Alan answered to this)
> > but
> > > > it is a different perspective that can be helpful.  BTW I never used on
> > my
> > > > life many to many but always a class representing the relationship, and
> > > > usually this brought advantages to the application.
> > > > I'm interested to know if other have different opinion.
>
> > > > ciao
>
> > > > Giorgio
>
> > > > On Thu, Mar 18, 2010 at 2:44 PM, Rowe <[hidden email]> wrote:
>
> > > >> I'm working on a project for school that involves building a course
> > > >> management system, and I need to use ManyToMany mappings for a few
> > > >> classes (for now, just the Student and Course classes). I haven't been
> > > >> able to find any documentation on the mappings which can give me a
> > > >> good example of how to implement a ManyToMany mapping, which I need
> > > >> since each Course has multiple students, and each student has multiple
> > > >> courses. Any help with setting this up is greatly appreciated.
>
> > > >> --
> > > >> You received this message because you are subscribed to the Google
> > Groups
> > > >> "WebVelocity" group.
> > > >> To post to this group, send email to [hidden email].
> > > >> To unsubscribe from this group, send email to
> > > >> [hidden email]<webvelocity%[hidden email]>
> > <webvelocity%[hidden email]<webvelocity%[hidden email]>
>
> > > >> .
> > > >> For more options, visit this group at
> > > >>http://groups.google.com/group/webvelocity?hl=en.
>
> > > >  --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "WebVelocity" group.
> > > > To post to this group, send email to [hidden email].
> > > > To unsubscribe from this group, send email to
> > > > [hidden email]<webvelocity%[hidden email]>
> > <webvelocity%[hidden email]<webvelocity%[hidden email]>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/webvelocity?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "WebVelocity" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email]<webvelocity%[hidden email]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/webvelocity?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "WebVelocity" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/webvelocity?hl=en.