similar to: habtm and belongs_to one table

Displaying 20 results from an estimated 7000 matches similar to: "habtm and belongs_to one table"

2006 Feb 16
1
HABTM -VS- belongs_to/has_many, for self-referential joins
Ok, David says on page 241 that sometimes a many-to-many relation with attributes are better implemented as an actual model instead of using HABTM. Well, I''ve got that situation and I can''t figure it out. All of the examples in the book have HABTM examples between 2 different tables, but I want to have a HABTM relation on 1 table with itself. (e.g., if I have a table Things,
2006 Mar 08
0
combining STI + polymorphism + rich self HABTM : how to ?
Hi all, I need to model simple typed polymorphic relations: ''John'' [''works_for''] ''Bill'' ''John'' [''speaks_for''] ''Microsoft'' ''Microsoft'' [''hold_shares_of''] ''Apple'' I''m having a hard time combining : - S.T.I.
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 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi. I have 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
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 Mar 22
2
habtm vs. has_many/belongs_to
In AWDWR David says (pg 232), "When a Join Wants to Be a Model: While a many-to-many relation with attributes can often seem like the obvious choice, it?s often a mirage for a missing domain model. When it is, it can be advantageous to convert this relationship into a real model and decorate it with a richer set of behavior. This lets you accompany the data with methods. As an example,
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 Feb 09
2
Polymorphic Associations
If anybody on edge familiar with this could help, that would be "great" :) I have different types of things I want to be "reviewable". So, instead of having a slew of HABTM... this new Polymorphic Associations schtick seemed like the best solution. I have everything setup as I thought it should be (so I think)... but it doesn''t appear to be working correctly. Here
2006 Mar 30
0
Polymorphic compatible with HABTM?
Can you use polymorphic with a habtm relationship? If so I would assume the join table would contain both the foreign key and the type for both sides of the table. The API documentation is unclear, although it may be out of date. I would prefer not to. I am trying to model a Person, who may be associated with many different models. A person may also be a member of one or more Teams, each of
2006 Jun 30
2
how to HABTM with STI ??
Hello all This is my first post so excuse the basic question. (and any repeats I just got an email saying this post was too big so I have re-submitted a smaller version) I was following the thread on http://lists.rubyonrails.org/pipermail/rails/2006-May/038988.html regarding the STI on HABTM for RoR. I have a very similar problem and was hoping for some help. I have the
2006 May 30
3
extra attributes in habtm
Hi, Posting here since issue tracking isn''t the best place to discuss. I can understand habtm is moving towards deprecating support for extra attributes in join_table, and to use :through for those cases instead. To clarify, patch<http://dev.rubyonrails.org/attachment/ticket/5216/habtm_join_table_test.patch1.diff>for #5216 <http://dev.rubyonrails.org/ticket/5216>
2006 May 24
2
"Stack Level Too Deep" issue in HABTM Unit / Functional Test
Hello guys. I was able to figure out that my "stack level too deep" error I was getting with my HABTM destroy method was the result of a bug in rails 1.0. I upgraded to 1.1.2 and now the views and any console-run commands for destroying AR objects linked together via HABTM work just fine. I have HABTM setup between stories and submissions. The issue is that the destroy methods in
2006 Apr 26
2
HABTM with ajax_scaffold
has anyone managed to do this? It works great for has_one, belongs_to type stuff, but i cant seem to get a HABTM setup going. Any demo code or advice greatly appreciated. Excellent work on this tool by the way its really great work. adam -------------- next part -------------- An HTML attachment was scrubbed... URL:
2008 Jun 13
1
Polymorphic :through associations
Could someone please help me with this association scheme? I am familiar with habtm as well as the :through association but this one has me stumped. Here is an example DB. Tags Table: ------------------------- id name Taggables Table: -------------------------- id tag_id taggble_type taggable_id For purposes of this example say that there are 2 other tables that can be tagged and their model
2006 May 03
2
habtm does not work with multiple tables
as i''ve read somewhere. this could be fixed easily. all the rails devs ( or whoever is responsible for the query building and executing part) have to do is to use the full qualifier in the sql statements (e. g. DB_Name.Tablename.Row). to solve that problem in the meanwhile one should define the :join_table in the habtm association with the full qualifier. -- Posted via
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
Imagine I want to track people, and the clubs that they belong to. table people with columns person_id, person_name table clubs with columns club_id, club_name And I have the association table: table clubs_people with columns person_id, club_id Now I know how to do this habtm between the two, in order to associate people with clubs that they belong to. However my application also needs a
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 Feb 09
2
select options for HABTM?
I''ve looked through the docs and the wiki and can''t figure out how to go about generating select options and the update function for an item that has a HABTM relationship. I have a ''parks'' table and the park model has a HABTM to the ''states'' table. On the park edit page, I''d like a multiple select box to appear with all states show,
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
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