similar to: Storing additional data on join tables with Rails

Displaying 20 results from an estimated 5000 matches similar to: "Storing additional data on join tables with Rails"

2006 May 28
7
Join table not being populated
Hello, I have the usual Categories and Products table scenario, mediated by a Categories_Products join table. When I create a new Product and into a given Category, I notice that my join table is not being populated. Shouldn''t the join Categories_Products table be populated? Thanks, gk -- Posted via http://www.ruby-forum.com/.
2006 May 27
7
How should I select rows from a join-model based on more than one association?
A concrete example: We''re building a system to organize the information about workshops being held in various conventions. A convention has more than one workshop, and each workshop can be held in more than one convention. Also each workshop has a host, who is specific to a workshop being held in a specific convention. For example, Matz may host an "Introduction to Ruby"
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_id]] ) the next section of controller code is a problem...
2006 Jul 10
7
What is has_many :through really buying you over HABTM?
So having just learned how to do has_many :through as opposed to HABTM, and then, being concerned that I wouldn''t get it to work, I started thinking about these two approaches. It seems to me that the _only_ problem that the HM:T (has_many :through) approach solves that HABTM doesn''t is the issue of the potential collision of id columns between your join table and one of
2006 Jun 05
5
adding habtm through migrations
Hello, I''m stuck, I''ve got a model Product and would like to add a new model called Category. Furthermore, I want to set up a many2many relationship between the mentioned models. the problem is that I do not know how to set the primary key in the categories_products table. this is what I''ve got in my migration file: create_table :categories do |t| t.column :name,
2006 Jan 02
1
ActiveRecord, << or push_with_attributes: update if exists?
In the Agile Rails book, on page 232 (PDF, 4th edition) there is an example of (within ActiveRecord) marking an article as read by a user at the present time. Short example code (from the book) here: class User < ActiveRecord::Base has_and_belongs_to_many :articles def read_article(article) articles.push_with_attributes(article, :read_at => Time.now) end # ... end
2006 May 16
4
Problems with multiple ''id'' columns in a join_table
I have a problem declaring a relationship through a join_table ; the SQL generated by ActiveRecord is correct, but there are two columns called ''id'', and the final object gets the ''wrong'' column ... Here''s a more detailed description of the data, code, and problem :- There''s a People table, with id, name, and a few things. Also a
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that HMT can do all of what HABTM can do and more. The question is: Should I stop using HABTM? Let''s take a simple case: A case has many categories For a given category, there are certain valid statuses Category has_and_belongs_to_many :statuses Status has_and_belongs_to_many :categories Question: Is
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 May 23
2
HABTM for Dummies Question
Taking time off from programming is always painful :-). I have the following Models: ==== class Tag < ActiveRecord::Base has_and_belongs_to_many :problems end class Problem < ActiveRecord::Base belongs_to :user has_and_belongs_to_many :tags end ==== And the following migrations: ==== create_table "problems" do |t| t.column "user_id", :integer
2006 Jul 05
7
HABTM join table has an "ID" column - is this an issue?
All, I''m building model objects for existing tables that I cannot modify. In AWDWR, Dave says "Note that our join table has no id column...The second reason for not including an id column in the join table is that AR automatically includes all columns from the join tables when accessing rows using it. If the join table included a column called id, its id would overwrite the id
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
2009 Jul 04
9
prevent orphan records
If I have belongs_to :user Do I need to have validates_presence_of :user_id ? Does Rails validate the presence of :user_id automatically if I have belongs_to :user? In other words, does Rails prevent against creating orphan records that belong to non-existent users? Thanks. -- Posted via http://www.ruby-forum.com/.
2006 Jul 05
1
newbie question: Mapping Collections
Hi, Day 3 with rails here. Forgive me. If this has been covered many times before, pls just point me at the article. I worked through the Rolling with Rails tutorial (http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) built up my cookbook. Things work great. I now want to add Ingredients to my app. So, a Recipe will have 1 or more Ingredients and any single ingredient can be
2006 Nov 29
4
how do I model self-referential entities?
Hi all - I am having some trouble figuring out how to model self-referential entities in Rails. I have a "group" model, which can have 0 or more "group" objects or 0 or more "user" objects. I tried creating a subgroup table that has a parent_group_id and a child_group_id as foreign keys but can''t figure out how to create the mapping in my ruby model
2006 Apr 20
4
Many to Many Category structure with itself
Basically, I''m trying to have a table called "categories" have a many to many relationship with itself. But I also want each catagory to be able to be "copied" into another category so it is essentially a child category to more than one parent. To me the obvious way of doing this is by creating another table called category_maps (and a model called CategoryMap).
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 21
3
has_many :through with a polymorphic join
Hi, Four tables: users, user_counties, uk_counties and us_counties. Each user has many counties, and each county has many users, so I decided to make user_counties a polymorph, so it can have counties from different countries (each country requires a completely different set of tables with a completely different set of properties, that''s why there''s one table for uk_counties and
2006 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip codes where counties have and belong to many zip codes. zip_codes (id, zip_code) counties (id, name) When I create the association table, the Rails way says to do the following: counties_zip_codes (county_id, zip_code_id). However, given that zip_codes.zip_code is itself a candidate key, I would much prefer to do the
2006 Jun 06
6
Linking two tables using a lookup table
Hi, How do I associate two different tables which have a lookup id (table) as common. I tried the has_many :table2, :through => look_up_table in my table1 model. Any hints? Thanks, Hari -- Posted via http://www.ruby-forum.com/.