Needing some help with many to many query

Hey i have a many to many relationship between Users &
PrivmessageThreads. This is where users will have many threads of
privmsgs, and vice versa. I trying to do a query on a PrivmsgThread
to just find the other user_id’s in the thread.

something similar to :
select * from PrivmsgsThreads_Users WHERE privmsg_thread_id = 1 &&
user_id != (current_user_id)

im using has_and_belongs_to_many in both my users and privmsgthread
model, but dunno how to do a query like this.

any help?

On 29 Oct 2007, at 01:34, Chubbs wrote:

Hey i have a many to many relationship between Users &
PrivmessageThreads. This is where users will have many threads of
privmsgs, and vice versa. I trying to do a query on a PrivmsgThread
to just find the other user_id’s in the thread.

something similar to :
select * from PrivmsgsThreads_Users WHERE privmsg_thread_id = 1 &&
user_id != (current_user_id)

Well you could do exactly that.

im using has_and_belongs_to_many in both my users and privmsgthread
model, but dunno how to do a query like this.

If you were using has_many :through, then you could just do
thread.thread_readers.user_ids (assuming thread_readers was your
through table)

Fred

On 29 Oct 2007, at 09:57, Chubbs wrote:

Please keep things on list.

something similar to :
select * from PrivmsgsThreads_Users WHERE privmsg_thread_id = 1 &&
user_id != (current_user_id)

Well you could do exactly that.

how would i go about doing it this way?

Well if you’ve got a raw chunk of sql,
self.class.connection.select_values ‘sql’

Assuming t is your thread, why not just t.user_ids and then just
exclude the ‘bad’ user id later on.

attributes are inside the many-to-many relationship
hatbm is a bit dead these days.

ok thanks for your help,

ill use the has_many :through and see how it goes,

thanks for advice

On Oct 29, 9:12 pm, Frederick C. [email protected]