similar to: has_and_belongs_to_many problem

Displaying 20 results from an estimated 300 matches similar to: "has_and_belongs_to_many problem"

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
2006 May 10
4
Single Table Inheritance problem
I have two tables I am using single table inheritance with: Page and Item. "Page" has many "Items"; "Item" belongs to "Page". Item Model: class Item < ActiveRecord::Base end class Article < Item belongs_to :page end Page Model: class Page < ActiveRecord::Base end class Issue < Page has_many :articles end In my controller, when I
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 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
2006 Jul 14
3
Migration not updating fields
So I have this fairly basic migration bit of code class AddCounterCache < ActiveRecord::Migration def self.up add_column ''products'', ''backlog_items_count'', :integer, :default => 0 end def self.down remove_column ''products'', ''backlog_items_count'' end end What I want to do in that is automatically
2006 Jan 09
6
has_and_belongs_to_many :self
Hi all I got the following class: class Member < ActiveRecord::Base has_and_belongs_to_many :buddies, :class_name => ''Member'', :join_table => ''members_have_buddies'', :foreign_key => ''member_id'', :association_foreign_key =>
2006 Mar 24
1
Problems with before_validation
Hi all My visitors can create party organisator profiles, and I want assign them as the creators (the field creator_id in the organisators table references a member in the members table). To do that I tried it with before_validation: def before_validation creator = Member.find 1 end Sadly, this does not work. The validation validates_presence_of :creator_id Still tells me, that
2006 Jan 19
0
Help with nested HABTM relationship
Hi, I am trying to perform a query with ActiveRecord that I want to put into a Rails application later. For now I just wrote it within a plain old Ruby script for easier testing. I am working with an existing database so I had to map some foreign keys myself. As you can see from the models below, the database has a structure of Prospectlists <=habtm=> Contacts <=habtm=> Accounts
2006 Jun 27
2
how to use scope with acts_as_list
i am working on a task management system for the company i work for. i just got the rails cookbook and am trying to use the section on creating a drag and drop sortable list. the tricky part is that my Task model references the User model in two different spots. i have one field for the creator of the task and another for the assignee. so in my Task model i have the following code: class
2007 Jan 03
3
Self-referential habtm with condition is broken
Here''s a simplistic model class. class Person < ActiveRecord::Base has_and_belongs_to_many :relatives, :class_name => ''Person'', :join_table => ''relatives'', :foreign_key => ''from_id'', :association_foreign_key => ''to_id'' has_and_belongs_to_many :brothers, :class_name =>
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM support this? That is: class Recipe < ActiveRecord::Base has_and_belongs_to_many :recipes, :join_table => "recipes_recipes" end More importantly -- how does RoR support MULTIPLE self-joins? I.e., to relate the table to itself via multiple join tables. SFAIK, HABTM won''t support multiple
2007 Nov 30
0
cross sell products - Options_from_collection_select ?
Hi I have collected some code for cross sell products on this website. CREATE TABLE products ( id INT NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, PRIMARY KEY (id) ); INSERT INTO products VALUES (1, ''alpha''); INSERT INTO products VALUES (2, ''beta''); INSERT INTO products VALUES (3, ''gamma''); CREATE TABLE cross_sells ( product_id
2006 Mar 25
0
Self-Referential Many-To-Many relationships where the relationship itself has data.
Trying to model a bunch of users that have friends that are other users. clearly a job for has_and_belongs_to_many, but the trick is, they have ratings for their friends. I have gone through the Rails Recipes book, and it seems like I''m trying to combine the self-referential many-to-many recipe (12) and the many to many relationships where the relationship itself has data recipe (16). So
2006 Feb 21
3
HABTM :insert_sql help
Hi all, I''m working with a legacy sqlserver db and I''m trying to override the insert sql in as defined in the HABTM method below(becasue the join has three primary keys), but I''m getting the error: ''undefined local variable or method `record'' for Project:Class'' has_and_belongs_to_many :people, :class => ''Person'',
2007 Oct 22
1
self-referential habtm: why are my keys null?
I''m trying to set up a directional self-referential HABTM to represent an arbitrary semi-hierarchical structure; it works for any data prepopulated into the db, but when I try to create a new relationship, I just get NULLs in both key columns (or 0''s if I turn on the no-null constraint). Here are the migrations: class CreateNodes < ActiveRecord::Migration def self.up
2010 Oct 06
2
reflect_on_association method
Hi all, I am having trouble trying to use reflect_on_association method with given the simplified model: class Order < ActiveRecord::Base belongs_to :contractor, :class_name => "BusinessUnit" end I expected the reflect_on_association method to return associated_foreign_key "contractor_id" but it returns "business_unit_id": ruby-1.9.2-p0 >
2007 Jul 26
1
Bi-directional self-referential HABTM
Hi, I''m having a little trouble figuring out how to make a self- referential HABTM bi-directional. I have a Employee class. Each employee can have a couple of bosses, who are also employees. The employee class has the following HABTM: has_and_belongs_to_many :bosses, :class_name => "Employee", :join_table => "bosses_courses", :association_foreign_key =>
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset objects, how do I do this? has_and_belongs_to_many :associated_assets, :class => "Asset", :foreign_key => ?????, :association_foreign_key => ????? Right now, my table has a :first_asset_id and a :second_asset_id, but I don''t see how the objects themselves are supposed to distinguish one from the
2006 May 01
0
Testing File Upload error
I am trying to build some tests where a file is uploaded and than processed by file column. Perhaps I am misunderstanding the new fixture_file_upload that was introduced in 1.1 but I can''t seem to get it to work correctly. I am trying to run a functional test to make sure that a redirect is made to the appropriate page from a create action. I create an issue and the issue can
2006 Apr 28
0
Add extra data to objects in an instance variable?
I am building an issue log with models: issues (belongs_to :user, has_many :comments) comments (belongs_to :issues, belongs_to :user) users (has_many :comments, has_many :issues) In the list view for the issues I wanted to print the time it was last updated. This should come from the most recent comment added, or if there are no comments added we fall back to the creation time of the issue: