similar to: how to insert data using has_and_belongs_to_many

Displaying 20 results from an estimated 4000 matches similar to: "how to insert data using has_and_belongs_to_many"

2007 Apr 03
2
has_many :through associated object ids assignment error
Hi, I have the following situation: class Article < ActiveRecord::Base has_many :readings has_many :users, :through => :readings end class Reading < ActiveRecord::Base belongs_to :article belongs_to :user end Now what I''m trying to do is: article = Article.new article.save! # user ids 1,2,3 exist in database, as does the article article.user_ids = [ 1, 2, 3 ] But I
2006 Jan 20
11
HABTM relations
Hi, I have 3 tables with HABTM relation. USERS -> QUOTE_TO_USER <- QUOTES Table QUOTE_TO_USER has 3 attributes: quote_id, user_id, component. I have a form where I can tie multiple users to QUOTE. This is easy one, thru "user_ids" (@quote[:user_ids] = @params[:quote][:user_ids]). In this form I have all users and I just check those I want to tie to this quote, however
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit books each month to be reviewed by other users. I have the following relationships defined: # the join model book_review.rb belongs_to :user belongs_to :book end book.rb # each book is reviewed by many users. This allows us to get the BookReview # objects associated with this book has_many :book_reviews,
2005 May 23
1
has_and_belongs_to_many dual insert error ?
Hi ! (See references at the end) I have a slight problem. Whenever I save one of my domain models, which contains an has_and_belongs_to_many relationship with another one, the relationships are doubled. My domain is a series of pictures, where each picture can be tagged with one or more words. So, a picture of my dog could be tagged "Jordy, Dog, Dog 2005", for example. In my
2006 Jul 26
8
team captain - habtm w/has_one...
the below... class User < ActiveRecord::Base has_and_belongs_to_many :teams class Team < ActiveRecord::Base has_and_belongs_to_many :users has_one :captain, :class_name => ''User'' produces the error... Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT * FROM users WHERE (users.team_id = 1) LIMIT 1 i
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 Nov 09
2
help with join tables and has_and_belongs_to_many
Hi, I have a user model and a privilege model. They have the has_and_belongs_to_many relationship. Here are the model defs: class User < ActiveRecord::Base belongs_to :status has_and_belongs_to_many :privileges end class Privilege < ActiveRecord::Base has_and_belongs_to_many :users end Now I have a migration script to create the join table and populate a few users with some
2005 Dec 28
1
making has_and_belongs_to_many save more elegant
When a user creates a post I also want to save all the tags associated with it. I do that in the post_controller like this presently: def save @post = Post.new(@params[:post]) @tags = Tag.new(@params[:tags]) @post.user_id = session[:id] if @post.save @tags.title.split('','').each do |tag| present_tag = Tag.find_by_title(tag.strip) present_tag =
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
2006 Aug 11
2
User Favorites
Hi there, I''m currently creating a simple (at least so I thought) structure of user favorites. Basically users can add certain ''objects'' to their list of favorites. Here is my current structure (simplified) class User has_many :favorites end class Book belongs_to :favorites end class Favorite belongs_to :user has_one :book end The table favorite just has a two
2006 Sep 28
5
Eager loading using find_by_sql
Here''s the problem I have the following models User - is a person Team - is a team Wherenote - snipet of info about a user''s whereabouts on a certain day Team has_and_belongs_to_many :users User has_and_belongs_to_many :teams has_many :wherenotes Wherenote belongs_to :user each Wherenote has a note_date On one page I want to pull back all the Users from a particular Team
2012 Jan 30
4
Reaching into a has_and_belongs_to_many - will :through work?
Hi. I''m hoping somebody can tell me that I''ve just gotten my syntax wrong and I can in fact do what I want to do. I''ve got a Group, and a Group has_many Campaigns. Campaign has_and_belongs_to_many Users (and, naturally, vice versa). So I''ve got a groups table, a campaigns table (that has a group_id), a campaigns_users join table (with campaign_id and
2012 Nov 13
1
help formatting data for clustering
Hi, I'm a R beginner. I have data of this form: user_id, brand_id1, brand_id2, ..... for example: 1 , 45 , 32, 45, 23 2 , 34 4, 11, 43, 45 I'm looking for the right procedure to be able to cluster users. I am especially interested to know which functions to use at each step. I am currently able to load the data in a data frame, each row's name being the user id. #extract user
2005 Dec 14
5
inserting multiple rows
I have table which stores multiple entries. Each row has user_id, game_id and a pick_id. On a page the user has to make load of choices. All this gets submitted. the html looks like so: <input type="hidden" name="game_id" value="3"> <input type="hidden" name="user_id" value="19"> <select name="pick[3]"> ....
2010 Oct 11
8
Nooby Stuck - "has_and_belongs_to_many" relationship
trying to set up a "has_and_belongs_to_many" relationship would very much appreciate the help, not sure what im doing wrong at all. Scheme.rb class Scheme < ActiveRecord::Base validates :schemename, :presence => true belongs_to :user has_many :levels, :dependent => :destroy has_and_belongs_to_many :works end Work.rb class Work < ActiveRecord::Base
2006 Aug 13
3
Render nothing; go nowhere
I am building an application that requires a C++ program to access the Rails web application using POST. Now, I just added user authentication to the mix and it has made things more interesting. I''m using basic authentication as shown in the AWDWR and Rails Recipes books. I can now get my C++ program to submit the user credentials to the login/login page. All I want the login page
2006 Jul 06
0
Paging with multiple tables/models
I''m looking for a smooth way to implement paging over a combination of two tables. My application tracks which books and movies you have borrowed from me. For reasons that make sense elsewhere in the application, these are seperated out into two tables: book_borrowers and movie_borrowers and therefore 2 different activerec objects: BookBorrower and MovieBorrower This particular screen
2014 Apr 16
0
Configure restful web service in rails
Hi, I am trying to create a Rest web service in my rails application. I need to configure urls for it as below. localhost:3000/book/book_id/new/param1/param2/param3/param4/... localhost:3000/book/book_id/next localhost:3000/book/book_id/delete I dont have a view pages for it since it returns in json format.Please help.So what is the best way to configure these urls via
2006 Jan 09
4
Problem with habtm and resulting SQL insert
Cheers, I have a problem with 1.0 and a habtm relationship between User and Article. I want to save all articles that users read. I have these models: class User < ActiveRecord::Base has_and_belongs_to_many :read_articles, :class_name => "Article", :join_table => "read_articles" ... end class Article < ActiveRecord::Base has_and_belongs_to_many :readers,
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
Has anybody noticed validates_uniqueness_of missing in rails 3.0 rc2? I''m not sure if this is a bug or I''m just doing something wrong. Here''s what I''m doing. Class 1: class Title < ActiveRecord::Base validates_length_of :language, :is => 3 validates_uniqueness_of :language, :scope => :book_id validate :language,