similar to: habtm on an array (or object.habtm.habtm)

Displaying 20 results from an estimated 4000 matches similar to: "habtm on an array (or object.habtm.habtm)"

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 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 Apr 05
5
Updating attributes in HABTM association
Hi, I am trying to find a way tp update attributes in a habtm association. I am trying to use the code from ticket #2462, but as my association_class_primary_key_name seems to be empty the generated sql code is corrupt. I hope thats not a problem of my model that this variable is empty. What would you recommend to update those attributes (rails 1.1) THANKS!!! -- Posted via
2006 Jun 01
3
Newbie: HABTM problems
I''m new to RoR and trying to make a HABTM relationship work. I have no problems with displaying the fields (after I pumped the data into MySQL manually outside of RoR), but when I try to edit a record, it =does= save the changes in the primary record, but =not= the join table. When I look in the development log, I see the update to the main table, but nothing about the join
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 Jun 11
2
HABTM Duplicates?
Hello all, I''m working on a small Rails site for a game I play that will be used to add new characters. Part of this addition process is choosing what skills the character will have. For this, in MySQL, I have a characters table and a skills table, as well as a characters_skills table that is used as the join table in the habtm relationship between the two. I am presenting the skills in
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 Jul 05
1
created_on in HABTM table getting parent dates
All of my HABTM tables receive the parent created_on/last_update_on dates whenever a record is inserted into these join tables. I don''t have any defaults in the database or anything else populating these tables. I assumed rails would populate these automagically. Is there something that needs to be done to get this to populate with the correct current timestamp instead of
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 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 Apr 30
2
HABTM: Find sorted by number of associations
Hi, I''ve been googling and searching the forums for some time but can''t seem to find exactly what I''m looking for. Suppose User HABTM Products (for example a favorites list). I would like to construct a single query for finding Products ordered by the number of Users that have flagged them as favorites. Although I can construct the query using SQL a with a
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table has another "non-joiny" attribute. I went from this: has_many_and_belongs_to :jobs, :join_table => ''tablename'', :foreign_key => ''x'', :association_foreign_key => ''y'' to this: has_many :jobs, :through =>
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 Aug 07
4
multiple habtm joins on the same two tables
i have a taskmanager type of project that i am working on, where i need to separate joins on the same two tables. i need one join for users that are assigned to the task, and another join for who has read the task, so they can tell which ones are new. any suggestions on the best way to accomplish this? thanks -- Posted via http://www.ruby-forum.com/.
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 Mar 24
4
habtm: attribute on join table
How do I retrieve the value of an attribute on my join table? For example: table ''people_places'' person_id place_id disposition The first two use foreign keys and all that (I get that part). The value of ''disposition'' is what I want. -- Posted via http://www.ruby-forum.com/.
2006 Mar 28
3
Rails 1.1: Is HABTM obsolete?
Does the new has_many :through and belongs_to :through obsolete (well, replace and essentially deprecate) has_and_belongs_to_many? Joe -- Posted via http://www.ruby-forum.com/.
2006 Jun 07
10
habtm "AND" find conditions
I have two tables and a join table for them e.g. books, authors in a many to many relationship (habtm) and a join table books_authors. I can successfully search for a book that has "author.id = 2 OR author.id = 4" but I am unable to search for "author.id = 2 AND author.id = 4" This is because the result of all the joins only has one author.id column so no single row has
2006 May 06
3
Storing additional data on join tables with Rails
Hi there I need to store additional attributes on join table. Searching the Wiki [1] revealed two possible methods: 1) push_with_attributes, as described by Justin Palmer [2]. Unfortunately, "this method is now deprecated" [3]. Even if it wasn''t, there seem to be inherent problems with that approach, for example with updating those additional attributes, though Joshua Muheim
2006 Aug 09
3
HABTM and getting to arrays from either direction
I didn''t find exactly an answer on this one, so I''d like to get a clarification from folks who live & breathe HABTM. class foo has_and_belongs_to_many :bars end class bar has_and_belongs_to_many :foos end (and yes, I have a bars_foos table in my db) def test_habtm bar = Bar.new foo = Foo.new foo.bars<<bar assert !foo.bars.empty? assert