Displaying 20 results from an estimated 200 matches similar to: "has_and_belongs_to_many :self"
2006 Jan 12
0
HABTM with conditional field in relation table
Hi all
I have members in my application, and every member can assign other
members as buddies.
class Member < ActiveRecord::Base
# Hat folgende Buddies
has_and_belongs_to_many :buddies,
:class_name => ''Member'',
:join_table => ''members_have_buddies'',
2006 Jan 11
4
Member.buddies.sort >> undefined method `<=>''
Hi all
I have a model Member that has a habtm relationship to buddies (also
members).
Now I wanted to sort them using sort, but this ends in an error
"undefined method <=>"! Where''s the problem here? Sorry, I''m still
beginning to learn Ruby. ;-)
Thanks
Josh
--
Posted via http://www.ruby-forum.com/.
2006 Jan 16
0
belongs_to with has_and_belongs_to_many
I''m having a problem with belongs_to and has_and_belongs_to_many.
Here''s a brief summary of the models involved:
class Member < ActiveRecord::Base
set_primary_key ''member_id''
has_and_belongs_to_many :projects, :join_table => ''projects__members''
has_many :projects, :foreign_key => ''created_by''
end
class
2006 Feb 27
4
2 belongs_to to the same parent table
Hello!
I have 2 table: users and buddies
User: id, name, ...
Buddy: id, user_id, user_buddy_id, ...
So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack,
there is a Buddy object: id=1, user_id=1, user_buddy_id=2
I can declare only one belongs_to in Buddy and one has_many in User. And
there is conflict if I had the second one (the first one is discarded)
class User
has_many
2005 Nov 22
11
Building a conditions clause (for find) of multiple optional params?
I want to be able to find items according to various params - category_id, member_id, type_id,
rating, etc. What I have now is something like:
if(@params[''category_id''])
@items=Item.find(:all, :conditions=>["category_id=?", @params[''category_id''])
elsif(@params[''category_id''] and @params[''member_id''])
2006 Feb 17
2
validate uniqueness of two fields
I have Proposals and Members and Members can vote for a proposal only once.
So, I have "Vote belongs_to :member, :proposal", but to make sure a member only votes
once, I want to make sure that there isn''t a vote in the db with that member_id and
proposal_id. I can just put the appropriate find in a vote.valid? but I wanted to make
sure I wasn''t missing a nice rails
2006 Jul 24
1
Relationship Conventions
Hi Team!
Just having a bit of trouble with the many-to-many relationship of the
same type.
Im trying to build a buddy list. So I have a users table and want to
allow each user to have a buddlist of users.
Ive tried having a User model and a Buddy model where the buddy model
has 2 fields user_id and a buddy_id but i cant get the buddy.name
methods to resolve when getting a list of buddies.
2006 Jun 15
2
AJAX form inside table - error
Hello,
I need to put an AJAX, form such that it is inside a table, and spans across
few rows.
But, what I am noticing is that, while submitting the form, the data in the
fields is not submitted.
If I move the form outside the table or inside a cell, things work OK, but not
when the form is inside the table and spans few rows. This problem is only
with AJAX forms, regular forms work perfect. I
2006 Aug 02
1
ActiveRecord: find_or_create with has_and_belongs_to_many --
I am attempting to use find_or_create on a foreign table with a
has_and_belongs_to_many relationship with my current table. I am doing
the following:
term = school.terms.find_or_create_by_code("FALL06")
the queries in the log show the expected SELECT statement to query if
there is a join table record between the school and term with code
"FALL06":
SELECT * FROM term
INNER
2006 Jun 15
1
has_and_belongs_to_many
My web server has a list of users, and each of them has a collection of
books. I want to save some certain number of books for each user,
including the book''s name, author, and display the information for the
user.
Which method should I use to store the subject information into each
user subject?
Do I have to create arrays to store it?
Thanks for help!
--
Posted via
2006 May 08
2
Queries with has_and_belongs_to_many relationship
I was able to create a has_and_belongs_to_many relationship for my app,
but now I''m not too sure how to write queries for it.
Basically, I have a table ''courses'' that has_and_belongs_to_many
''categories'' and vice versa
So I''m trying to figure out how I would find only the courses that
belong to a category that I specify.
Let''s
2006 May 26
0
has_and_belongs_to_many with fk constraints?
Hi folks,
I''m wondering if it''s possible to use foreign key constraints on the join
tables of a has_and_belongs_to_many relation. Specifically, I get this
error when I try and delete a model I''m using, named saved_search, which is
many-to-many with neighborhoods. Any ideas? Thanks for any help. :-)
-Eric
Code:
@saved_search.destroy
Error:
Mupdate or delete on
2006 Apr 01
3
has_and_belongs_to_many construction
Hi there,
I''ve got a table construction like this:
presentation contactstate
Hilton new
Mc Donalds emailed
etc. called
visited
etc.
Now i''ve created an join table presentationcontactstate with extra
fields like comment and date time. so i know for example when i called a
specific presentation.
Now
2006 Apr 06
3
has_and_belongs_to_many find
Say I have a post model that has_and_belongs_to_many :categories, and a
category model that has_and_belongs_to_many :posts. So I have a
categories_posts table to do the join. That''s all find and dandy.
However I want to be able to find all the posts that belong to a
specific category.
I tried Post.find_by_category(:id) but that doesn''t work.
Does anyone have any insight?
2006 Apr 21
0
collection_select has_and_belongs_to_many update_attributes
I know there have been threads on this before but I was thinking
shouldn''t multiple collection_select automatically update habtm
relations when you update_attributes?
In order to get multiple collection_select to work I use:
collection_select(:user, :group_ids, Group.find(:all), :id,
:name,{},{:multiple=>'''',:name=>''group[id][]''})
In fact if I
2006 Mar 07
1
has_and_belongs_to_many tags
I''m trying to create a search where I can find pages by their tag name.
Here''s a sample of my code (not working).
@tags = Page.find(:all, :conditions => ["#{:tag.name} LIKE ?",''%'' +
@params[''searchtags''] + ''%'' ])
My enviroment:
I''ve got a table called tags, and a table called pages, both with a
2006 Mar 09
2
has_and_belongs_to_many -- how to create test fixtures?
Hallo -- can anyone offer me any pointers as to I should handle
many-to-many relationships in Rails tests?
Cheers,
doug.
--
Posted via http://www.ruby-forum.com/.
2006 Feb 10
0
Deleting the association entry for has_and_belongs_to_many when one object is destroyed
I know that for has_many, and has_one.
I can do :dependent => true and the associated object will be
destroyed when the main object is destroyed.
However, there does not seem to be a dependent like option for
has_and_belongs_to_many.
Is there one I do not know of? Is there a simple solution to this?
Thanks,
Brian
--
www.kenlet.com
2006 Jan 03
0
has_and_belongs_to_many include problem
hey,
i have users who are in groups, and i have a search form, where i can search on
group, user lastname, and user firstname.
All this is also with pagination.
these are my models
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
in my controller i do this
THIS works (but in need pagination)
@users2
2005 Dec 14
0
how to get these records in has_and_belongs_to_many relation
hey,
i my database i have users and groups, each user can get in different groups
my db structure:
table groups: id, name, basegroup, firm_id
table users: id, firstname, lastname, email
table groups_users: group_id, users_id
my relation is a many to many:
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many