[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Greg Donald
On Thu, Sep 17, 2009 at 3:39 PM, Marnen Laibow-Koser wrote: >> Umm yeah, well.. I work in genetics research and I can tell you I have >> this exact scenario _all the time_. > > And you use this sort of data model for it? Yeah, it turns out two models that share a join model is very common. --

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread dinoD
thanks for all the replies. just to clarify my intent, i am associating keywords with a set of documents, and the more times a keyword is associated with particular document, the more it is weighted as being relevant to that keyword, but it must be the exact same keyword, that's why i do this: a

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Marnen Laibow-Koser
Greg Donald wrote: [...] > > Umm yeah, well.. I work in genetics research and I can tell you I have > this exact scenario _all the time_. And you use this sort of data model for it? > Genetic pathways repeat > throughout any genome, human or other. Your assumption that > everyone's data is l

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Marnen Laibow-Koser
Robert Walker wrote: [...] >> a.bs << b >> a.bs << b >> a.bs << b > > This is somewhat unclear, but it appears from your code this is adding > the same b three times. So yes, if you did exactly as shown all three > association to that same b would be deleted. This appears to be what Dino was a

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Greg Donald
On Thu, Sep 17, 2009 at 2:36 PM, Marnen Laibow-Koser wrote: > The issue here is not the presence or absence of a join model -- after > all, for a simple habtm, there's no reason at all to introduce the extra > class.  Rather, this is a reflection of the fact that the OP is trying > to do somethin

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Robert Walker
dinoD wrote: >> b = B.first # Find the b you want to remove association to. >> a.bs.delete(b) >> >> From has_and_belongs_to_many doc: >> >> collection.delete(object, �) >> Removes one or more objects from the collection by removing their >> associations from the join table. > > thanks for the rep

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Marnen Laibow-Koser
Greg Donald wrote: > On Thu, Sep 17, 2009 at 1:54 PM, dino d. wrote: >> a.bs << b >> >> this creates 3 records in the join table. >> >> Is there any way for me to remove only one of these? �I can only seem >> to remove all of them. > > > This is exactly why I use join models and ignore > has_an

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Robert Walker
dino d. wrote: > a.bs << b > a.bs << b > a.bs << b > > this creates 3 records in the join table. > > Is there any way for me to remove only one of these? I can only seem > to remove all of them. b = B.first # Find the b you want to remove association to. a.bs.delete(b) >From has_and_belongs_t

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread dinoD
> b = B.first # Find the b you want to remove association to. > a.bs.delete(b) > > From has_and_belongs_to_many doc: > > collection.delete(object, …) > Removes one or more objects from the collection by removing their > associations from the join table. thanks for the reply, unfortunately this d

[Rails] Re: remove 1 HABTM association at a time

2009-09-17 Thread Greg Donald
On Thu, Sep 17, 2009 at 1:54 PM, dino d. wrote: > > hi - i have two models, A and B, and each habtm the other > > if I do > > a  = A.new > b = B.new > > a.bs << b > a.bs << b > a.bs << b > > this creates 3 records in the join table. > > Is there any way for me to remove only one of these?  I can