Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Single Table HABTM
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Valery Kvon  
View profile  
 More options Sep 1 2008, 12:09 pm
From: Valery Kvon <adda...@gmail.com>
Date: Mon, 1 Sep 2008 20:09:31 +0400
Local: Mon, Sep 1 2008 12:09 pm
Subject: Single Table HABTM
Hi, all

I'm looking for a trick how to get something like that:

obj1 = SmthClass.new
obj2 = SmthClass.new

obj1.connections << obj2

 >> obj1.connections
=> obj2

 >> obj2.connections
=> obj1

??

PS: The first solve is to make the third join model, and put them all  
necessary has_many + has_many relationship, then give the join model  
optional method using transaction etc, so it's inevitable to have two  
identical strings in the join models' database table (to obj1 and  
obj2)...? Or i can write some handler to seek obj1 and obj2 using  
'their own' foreign keys one by one through each other (two has_many  
methods with two different foreign keys)?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Sep 1 2008, 3:29 pm
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Mon, 1 Sep 2008 15:29:45 -0400
Local: Mon, Sep 1 2008 3:29 pm
Subject: Re: [Rails] Single Table HABTM

This earlier thread might be helpful.

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/...

Regards,
Craig


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Valery Kvon  
View profile  
 More options Sep 1 2008, 4:25 pm
From: Valery Kvon <adda...@gmail.com>
Date: Tue, 2 Sep 2008 00:25:10 +0400
Local: Mon, Sep 1 2008 4:25 pm
Subject: Re: [Rails] Re: Single Table HABTM

On 01.09.2008, at 23:29, Craig Demyanovich wrote:

Thanks, I saw it!  But unfortunately this method makes only "one-way"  
association and not vice versa (if i'm not mistaken).
Exactly I need - vice versa associations. I thought the only way to do  
it is to have two strings in the database (obj1 to obj2 and obj2 to  
obj1). Where is the trick?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Sep 1 2008, 4:55 pm
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Mon, 1 Sep 2008 16:55:53 -0400
Local: Mon, Sep 1 2008 4:55 pm
Subject: Re: [Rails] Re: Single Table HABTM

Ah. I haven't done that yet. A Google search for

"many-to-many" "self-referential" rails

turns up some hits that could be useful.

Regards,
Craig


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Valery Kvon  
View profile  
 More options Sep 1 2008, 5:00 pm
From: Valery Kvon <adda...@gmail.com>
Date: Tue, 2 Sep 2008 01:00:58 +0400
Local: Mon, Sep 1 2008 5:00 pm
Subject: Re: [Rails] Re: Single Table HABTM
Ok, thanks, maybe i'll get something intresting or write it myself )
On 02.09.2008, at 0:55, Craig Demyanovich wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Valery Kvon  
View profile  
 More options Sep 1 2008, 5:16 pm
From: Valery Kvon <adda...@gmail.com>
Date: Tue, 2 Sep 2008 01:16:39 +0400
Local: Mon, Sep 1 2008 5:16 pm
Subject: Re: [Rails] Re: Single Table HABTM
This is similar: http://hideto.javaeye.com/blog/75887

What are you think? I guess, there is no transaction improvements to  
be a super nice :)

On 02.09.2008, at 0:55, Craig Demyanovich wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Sep 1 2008, 7:14 pm
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Mon, 1 Sep 2008 19:14:18 -0400
Local: Mon, Sep 1 2008 7:14 pm
Subject: Re: [Rails] Re: Single Table HABTM

Actually, according to a reply in another thread, you could build on what I
shared earlier. First, declare the habtm as described before, then declare
another habtm named as you want and with the foreign_key and
association_foreign_key swapped around.

class User < ActiveRecord::Base
  has_and_belongs_to_many :friends,
    :class_name => "User",
    :join_table => "users_friends",
    :foreign_key => "user_id",
    :association_foreign_key => "friend_id"
  has_and_belongs_to_many :reverse_friends,
    :class_name => "User",
    :join_table => "users_friends",
    :foreign_key => "friend_id",
    :association_foreign_key => "user_id"
end

Does that work?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Valery Kvon  
View profile  
 More options Sep 2 2008, 4:10 am
From: Valery Kvon <adda...@gmail.com>
Date: Tue, 2 Sep 2008 12:10:04 +0400
Local: Tues, Sep 2 2008 4:10 am
Subject: Re: [Rails] Re: Single Table HABTM
Not exactly: association methods differ from each other (.friends  
and .reverse_friends):
 >> friend1.friends
=>  friend2

 >> friend2.reverse_friends
=> friend1

that is not what i want

On 02.09.2008, at 3:14, Craig Demyanovich wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Sep 2 2008, 7:47 am
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Tue, 2 Sep 2008 07:47:18 -0400
Local: Tues, Sep 2 2008 7:47 am
Subject: Re: [Rails] Re: Single Table HABTM

So you like the result but not the name of the association?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Valery Kvon  
View profile  
 More options Sep 2 2008, 10:32 am
From: Valery Kvon <adda...@gmail.com>
Date: Tue, 2 Sep 2008 18:32:55 +0400
Local: Tues, Sep 2 2008 10:32 am
Subject: Re: [Rails] Re: Single Table HABTM

That's right.

On 02.09.2008, at 15:47, Craig Demyanovich wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Sep 2 2008, 10:47 am
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Tue, 2 Sep 2008 10:47:00 -0400
Subject: Re: [Rails] Re: Single Table HABTM

I doubt that you can have two habtm associations with the same name, but
I've never tried it. I suggest you try it. If it works, you have what you
want. If it doesn't work, I suggest finding unique names that you like for
each association. Either way, please share your findings.

Regards,
Craig


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »