Cached manytomany problem?

0 views
Skip to first unread message

Casey Corcoran

unread,
May 5, 2008, 12:51:07 PM5/5/08
to transf...@googlegroups.com
Support Info:
CF8, Transfer 1.0, SQL Server 2005, Windows Server 2003

I'm sure I'm misunderstanding something, but here's my problem:

I have a Category object which has a manytomany relationship with a
Course object, and the Course object in turn has a manytomany
relationship with the Category object, both through the join table
CategoryCourses. When I add a Course to a Category:
myCategory.addcourses(myCourse) it works fine however on my edit Course
page I have a listing of which Category the Course is in and this only
gets updated if I reset the application. I'm using lazy loading on both
sides, how do I make sure they stay in sync in the cache?

Thanks in advance,
Casey

Mark Mandel

unread,
May 5, 2008, 2:15:28 PM5/5/08
to transf...@googlegroups.com
Casey,

From what I think you're asking - you're trying to do bidrectional manytomany?

You can only do one set of configuration per relationship, so
bideirectional manytomany is not supported.

It is something that people have discussed in the past, so it may be
considered for the future.

Mark

--
E: mark....@gmail.com
W: www.compoundtheory.com

Casey Corcoran

unread,
May 5, 2008, 3:07:04 PM5/5/08
to transf...@googlegroups.com
That sounds right Mark, I figured I was just misunderstanding the way it
worked, for now I'm just making sure both directions get updated at the
same time.

Thanks!
Casey

r.tu...@forthmedia.com

unread,
May 8, 2008, 1:57:05 PM5/8/08
to transfer-dev
> That sounds right Mark, I figured I was just misunderstanding the way it
> worked, for now I'm just making sure both directions get updated at the
> same time.

Hi Casey - I have the same situation. How are you forcing the updates?
For example if I have a save event I am looping through the children
by ID doing a discard(), get(), addManyToMany() however I'm not sure
if this is the best approach. Serialisation is something I haven't
considered yet either. The caching mechanisms certainly turbo-charge
everything, but I'm having trouble getting my head around it.

Cheers

Richard

Casey Corcoran

unread,
May 8, 2008, 2:01:16 PM5/8/08
to transf...@googlegroups.com
I just ended up doing something like this:

category.addCourses( course );
course.addCategories( category );
transfer.save(category);
transfer.save(course);

I put checks in to make sure they didn't have the relationship already,
then the remove is the same idea just with remove instead of add.

Hope that helps!

Casey

r.tu...@forthmedia.com

unread,
May 8, 2008, 2:21:27 PM5/8/08
to transfer-dev
Ah - so you don't actually have ManyToMany relationships, but
OneToMany on either side with the join table?

Casey Corcoran

unread,
May 8, 2008, 2:24:29 PM5/8/08
to transf...@googlegroups.com
Well, it's a manytomany on both sides so in theory they should stay
synced up, but the caching spoils that plan. :)

r.tu...@forthmedia.com

unread,
May 8, 2008, 2:31:21 PM5/8/08
to transfer-dev
Ok - cheers - and thanks for pointing this out in the first place

Brian Kotek

unread,
May 8, 2008, 2:31:24 PM5/8/08
to transf...@googlegroups.com
You *can't* do bidirectional relationships with any of the link types and use the cache. Even without the cache there may be issues lurking but I'm not positive. The bottom line is: don't do this.

r.tu...@forthmedia.com

unread,
May 8, 2008, 3:18:42 PM5/8/08
to transfer-dev
Thanks Brian - it's a pity though. There are a lot of real life many-
to-many situations where the objects on both side have equal claims on
composition and it "seems" to work... but I'll take your word for it!

On May 8, 8:31 pm, "Brian Kotek" <brian...@gmail.com> wrote:
> You *can't* do bidirectional relationships with any of the link types and
> use the cache. Even without the cache there may be issues lurking but I'm
> not positive. The bottom line is: don't do this.
>
> On Mon, May 5, 2008 at 3:07 PM, Casey Corcoran <casey.corco...@gmail.com>

Mark Mandel

unread,
May 8, 2008, 5:40:03 PM5/8/08
to transf...@googlegroups.com
I've written down a short spec for a bidirectional m2m, but nothing is
set in stone yet.

Mark

--
E: mark....@gmail.com
W: www.compoundtheory.com

r.tu...@forthmedia.com

unread,
May 8, 2008, 11:08:05 PM5/8/08
to transfer-dev
Thanks Mark

On May 8, 11:40 pm, "Mark Mandel" <mark.man...@gmail.com> wrote:
> I've written down a short spec for a bidirectional m2m, but nothing is
> set in stone yet.
>
> Mark
>
> On Fri, May 9, 2008 at 5:18 AM, r.tugw...@forthmedia.com
>
>
>
> <r.tugw...@forthmedia.com> wrote:
>
> > Thanks Brian - it's a pity though. There are a lot of real life many-
> > to-many situations where the objects on both side have equal claims on
> > composition and it "seems" to work... but I'll take your word for it!
>
> > On May 8, 8:31 pm, "Brian Kotek" <brian...@gmail.com> wrote:
> >> You *can't* do bidirectional relationships with any of the link types and
> >> use the cache. Even without the cache there may be issues lurking but I'm
> >> not positive. The bottom line is: don't do this.
>
> >> On Mon, May 5, 2008 at 3:07 PM, Casey Corcoran <casey.corco...@gmail.com>
> >> wrote:
>
> >> > That sounds right Mark, I figured I was just misunderstanding the way it
> >> > worked, for now I'm just making sure both directions get updated at the
> >> > same time.
>
> >> > Thanks!
> >> > Casey
>
> --
> E: mark.man...@gmail.com
> W:www.compoundtheory.com
Reply all
Reply to author
Forward
0 new messages