search for: has_and_belongs_to_many

Displaying 20 results from an estimated 441 matches for "has_and_belongs_to_many".

2006 Apr 16
6
still learning maintaining data with join tables
Class Role has_and_belongs_to_many :users Class User has_and_belongs_to_many :roles Class RolesUsers has_and_belongs_to_many :roles has_and_belongs_to_many :users According to the logs...I''m good through here @roles_users = RolesUsers.find(:all, :conditions => ["user_id = ?", params[:users_...
2005 Mar 01
0
has_and_belongs_to_many problem
I''m having a problem with a has_and_belongs_to_many (habtm) association between two models with extra attributes. I''m writing a comic book database, and each issue has many creators on it. Thing is, some creators perform multiple duties. They may write one issue, draw another, etc. However, if I add a creator twice to an issue and try t...
2006 Feb 28
8
HABTM count table
Hello, I have a question about HABTM and counting records. I have these models class Sort < ActiveRecord::Base has_and_belongs_to_many :reports end class Report < ActiveRecord::Base has_and_belongs_to_many :region has_and_belongs_to_many :subjects has_and_belongs_to_many :sorts end And i would like to get a count like @sort.reports.count The problem is get this query: SELECT COUNT(*) FROM reports WHERE (reports_s...
2006 Mar 20
2
AHHHhhhhh... has_and_belongs_to_many, that is going on?
..."johnson", "reviewer_id"=>"1"}>] >> r.reviewers_score_cards NameError: uninitialized constant ReviewersScoreCard from ...dependencies.rb:195:in `const_missing'' from ...association_proxy.rb:12:in `initialize'' from ...has_and_belongs_to_many_association.rb:5:in `eval'' from ...association_proxy.rb:12:in `initialize'' from ...has_and_belongs_to_many_association.rb:5:in `initialize'' from ...associations.rb:753:in `new'' from ...associations.rb:753:in `reviewers_score_cards&...
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
...rection. Database Schema: table employees id name table projects id name table project_roles id name table project_members id employee_id project_id role_id I then have the following ActiveRecord objects: class Employee < ActiveRecord::Base has_and_belongs_to_many :project_members, :join_table => "project_members", :class_name => "ProjectMember" end class Project < ActiveRecord::Base has_and_belongs_to_many :project_members, :join_table => "project_members", :class_name => "ProjectMember" end class P...
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 b...
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...
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
...a couple of best practices questions regarding polymorphic associations, naming join tables and user permissions. Currently I have implemented the user authentication model from the rails recipes book. Basically it goes something like this: MODEL CLASSES: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role < ActiveRecord::Base has_and_belongs_to_many :users has_and_belongs_to_many :rights end class Right < ActiveRecord::Base has_and_belongs_to_many :roles end TABLES: users rights roles rights_roles (habtm join table) roles_users (habtm join table) All fairly s...
2006 Feb 26
5
Help On Associations Extension.
Hi to all, I''m needing some help here ... I want to do an extension on a has_and_belongs_to_many to build a custom add method to the association. i have a table locations that has a many-to-many association with a tags tabel using a locations_tags table. i want to add a method to the Location has_and_belongs_to_many association so that i can do something like this on the location model: m...
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 that leads...
2012 Sep 12
2
how to generate third table in test database
hi all, has_and_belongs_to_many :cows has_and_belongs_to_many :milkmans i am using has_and_belongs_to_many in my app.I know this will create third table internally cows_milkmans in mysql database. when i migrate develpoment database i have table cows_milkmans. Good no Problem till now. Now a problem start When i migrate...
2006 Aug 16
3
Question RE Rails associations
Hi, I am new to Ruby and Rails programming and am having difficulty with the following scenario... Consider the following model: class Studio < ActiveRecord::Base has_many :movies has_and_belongs_to_many :actors end class Movie < ActiveRecord::Base belongs_to :studio has_and_belongs_to_many :actors end class Actor < ActiveRecord::Base has_and_belongs_to_many :studios has_and_belongs_to_many :movies end The underlying database structure is as follows: studios id: integer mov...
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
...n, but is not yet a member. So I have a second association table table clubs_people_applied with columns person_id, club_id In other words, I need TWO habtm''s between the same two tables. Where this is failing I think is in the model definitions: Class Person < ActiveRecord::Base has_and_belongs_to_many :clubs, :join_table => clubs_people has_and_belongs_to_many :clubs, :join_table => clubs_people_applied ... end The rails api says that "WARNING: If you?re overwriting the table name of either class, the table_name method MUST be declared underneath any has_and_belongs_to_many dec...
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 form, the tags are presented to the user in a...
2006 Jan 19
5
limits of has_and_belongs_to_many
...''id'' within RoR instead. I''ve been successful in using a join table with two fields named ''recipe_id'' and ''tag_name'' to relate a table called Recipes with a table called Taggs, using this model: class Recipe < ActiveRecord::Base has_and_belongs_to_many :taggs, :join_table => "recipes_tagnames" , :association_foreign_key => "tag_name" end In this case both Recipes and Taggs have a field called ''id'' as their primary key, i.e., they are being joined by Recipes.id = Recipes_Tagnames.recipe_id AND Recip...
2006 Apr 03
3
Read Only Error Since 1.1?
Since I upgraded to 1.1, I am getting ''ActiveRecord::ReadOnlyRecord'' exceptions when trying to save a specific record. I read up on ActiveRecord::Base.readonly? but I don''t think the condition there (objects pulled in from a certain JOIN type) applies. Here''s my code that is throwing the exception: @company = session[:company] @company.bytes_used =
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 "saved_searches" violates forei...
2006 Jan 13
2
newbie: access model inside a model
...outside the examples in the book and walking against some things I didn''t learn yet. so here''s the question: Is it possible to access one model from within another? Actually I have a Many to Many relationship between tables and I''m trying to realize this without "has_and_belongs_to_many". Maybe someone can push me in the right direction. Kind regards, Jeroen van Doorn
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...
2005 Oct 05
0
has_and_belongs_to_many on legacy DB
I am working with mapping ActiveRecord onto a legacy database. All is going well (using set_table_name, set_primary_key, etc), but I can''t get my many<=>many relationships to work. My contrived example of the situation: Student has_and_belongs_to_many Teachers. This is mapped via table student2teacher where the foreign keys are studentId and teacherId. The primary key in Student is studentId, and in Teacher is teacherId. However, when I run my unit tests I am getting this error: Mysql::Error: Unknown column ''j.student_id'' in &...