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?

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

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.

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)

i could use a has_many :through but i thought i read somewhere i should try to avoid using them if i didnt need to? good only if 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