similar to: has_and_belongs_to_many find

Displaying 20 results from an estimated 2000 matches similar to: "has_and_belongs_to_many find"

2006 Jul 12
1
odd habtm behavior? or is it me?
Hello List, I''m a bit spent on this problem, and my code might be whack. I seem to be encountering a problem where the primary key on a join table is not being resolved correctly. I will elaborate after some code bits. I am creating the join table using migrations, and relevant model code is this: class Post < ActiveRecord::Base has_and_belongs_to_many :records
2006 Apr 13
2
Automatic finder
It looks rails automatically creates a "finder" method on models that have a "belongs_to". So I tried this in the console: c = Category.find(2) chunks = Chunk.find_by_category(c) chunks is always returned as an empty array. When I know have some chunks with a category_id of 2. Should the find_by_category do what I think it should be doing or am I completely off base?
2005 Dec 16
3
Adding methods to models
All, This is more of a theoretical question I suppose - I''m looking for what the consensus is for the "correct" approach in Rails/MVC. I have a standard security model where a User can have many Roles. There is a User model, a Role model, and in the db, a linking table, etc. Each role has a name as well as a category (say, name="waiter", category="restaurant
2006 Feb 14
1
Another HABTM Question
Hi there, I have a question on what would be the best way to save a HABTM model. A posting habtm categories, and a category habtm postings. class Category < ActiveRecord::Base has_and_belongs_to_many :postings end class Posting < ActiveRecord::Base has_and_belongs_to_many :categories end In my blog_controller, where the actual posting is saved, is where I think I''m
2006 Mar 20
2
AHHHhhhhh... has_and_belongs_to_many, that is going on?
I don''t have a class by the name of "ReviewersScoreCard", yet my many to many configuration looks as follows. And, these errors while running some simple test with ./script/console is giving me a headache: ./script/console Loading development environment. >> r = Reviewer.find_first => #<Reviewer:0x19d0a48 @attributes={"id"=>"1",
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 11
1
ActiveRecord collection_select and has_and_belongs_to_many
Hello everyone, first post to the list and a relative newbie to Rails development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I would kick the tires on Rails to see if it can speed up development for internal applications. Anyway, I am running into a problem that is just driving me crazy and everything I read on the net doesn''t seem to help. I was hoping someone here might
2012 Sep 08
3
Polymorphic has_and_belongs_to_many association
Hi, I''m currently having the situation where I have to implement a polymorphic has_and_belongs_to_many by introducing an in between model that handles all the "has_many :as" and "belongs_to :polymorphic" association implementations... and is not doing anything else. Thing I don''t like it here is, I am unnecessarily loading AR instances only to execute SQL
2006 Jan 19
5
limits of has_and_belongs_to_many
I''m experimenting with Rails on the Recipes example first before I dive into applying it to my intended application. I''m exploring which will be more work: to rename all the primary id''s in the legacy database, or to work around the fact that the primary id''s are not called ''id'' within RoR instead. I''ve been successful in using a
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 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/.
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
2006 May 23
7
has_and_belongs_to_many question
Hello, I am trying to make the "switchover" to programming my apps in Rails and have a question about database structure. In the past i would structure a many to many like this: categories ---------------------------------------------------- | id | name | ---------------------------------------------------- 1 Some Category 2 Another
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
2005 Mar 02
1
Cleaning up has_and_belongs_to_many?
Does has_and_belongs_to_many know to delete an object when the last reference to it is removed? In my case I have Receiver <<->> Message (with a join table of course), but have noticed that when the last receiver removes a message from the association the message still exists. Before adding code to manage this situation I want to check to see if I am missing something? --
2006 Dec 25
2
how to insert data using has_and_belongs_to_many
I''am newbie in RoR, so my question might look stupid, but I stuck in one thing. I''ve created 3 tables: users{ id, user } books { id, book } books_users{ book_id, user_id} Model class Book< ActiveRecord::Base has_and_belongs_to_many:users I can''t figure out how to insert data to the books_users table. For example users post info about new book and information
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
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 =
2005 Dec 23
6
Stories with many tags, tags with many stories, has_and_belongs_to_many howto?
Hi, I began experimenting with habtm relationships, and so I created a stories table, a tags table, and a stories_tags table referencing the former 2. When I create a "story", I want to add several tags to it. Then, the model should create those tags and link them to the respective stories, and for the tags that already exists, just link them to the story. I tried something like
2006 May 27
10
Displaying Hours
Here''s an intersting one: I have a client who wants to store hours of operation of a business for their RoR web app. I came up with a solution, but I really don''t like it. I have a MySQL table that has these fields monday_start, monday_end, tuesday_start, tuesday_end, etc., all as time fields. That''s all find and dandy. The kicker is, the client wants the hours to