Displaying 20 results from an estimated 20000 matches similar to: "REST - Implementing HABTM in the real world"
2006 Jul 27
0
CRUD, REST and associations
Let''s say I have the model class Reader and Magazine, connected by join 
model Subscription. It looks something like this
class Reader < ActiveRecord::Base
  has_many :subscriptions, :dependent => :delete_all
  has_many :magazines, :through => :subscriptions
  validates_presence_of :name
end
class Magazine < ActiveRecord::Base
  has_many :subscriptions, :dependent =>
2006 Jul 27
0
Controllers, Models, and Validations...
Hello,
After listening to DHH''s 2006 RailsConf keynote, I decided to take a
leap on my current application and do a little more re-organizing to
make it more CRUD-based. As such, I ended up changing some things
around to get this (simplified):
User has_many :enrollments, :conditions => ''status > 0''
User has_many :schools, :through => :enrollments
User has_many
2007 Oct 15
0
converting from HABTM to has_many :through
Hello,
I have a has_and_belongs_to_many relationship that I''ve realized I need
to add additional attributes to. So I''m converting it to a has_many
:through (HMT) relationship. This is the first time I''ve used an HMT,
and it seems like I''m using too much code. I couldn''t figure out how to
get the join model objects to update automatically as a result of
2006 Apr 18
1
habtm and belongs_to one table
I have the following:
Posts belong to a User
Posts may be Monitored by many Users
How do you characterize this?
class Post < ActiveRecord::Base
  belongs_to :user
  has_many  :monitors
class Monitor < ActiveRecord::Base
  has_many :posts, :as => user
class User < ActiveRecord::Base
  has_many :posts  # when a user *does* a post
  belongs_to :monitor, :polymorphic => true
--
2006 May 18
3
Model Madness: habtm vs through
This has me scratching my head:
a Person has many Things
a Person has many Collections
a Collection has many Things
  ...Things in a Collection are ordered
  ...Things in a Collection can be related to (created by) any User
  ...a collection has additional attributes, such as a name etc
I am confused about habtm in rails (especially when using 
acts_as_habtm_list) vs. going the :through route.
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 Dec 27
0
HABTM Checkboxes - Adding/Updating Users to a Project
Hello all,
I''m trying to create a HABTM checkbox action that adds/updates ''users''
to a ''project''.
I have the following laid out.
---------------------
TABLES
---------------------
  create_table "assignments", :id => false, :force => true do |t|
    t.column "project_id", :integer, :default => 0, :null => false
   
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 Jan 21
0
Display options from HABTM
I have a large certifications table that I would like to have a little 
more controll over, it is part of a HABTM relationship.
-----------------------------------
db''s (simplified)
>certifications
id
course
>employees
id
department_id
type_id
name
>departments
id
name
>types
id
kind
>certifications_employees
certification_id
employee_id
2006 Feb 20
0
No Magic for HABTM forms?
Hi,
I posted yesterday asking how to get form tags to reference the  
associated objects in a habtm relationship. I was hoping for Rails  
Magic, but it looks like Rails doesn''t have habtm magic beyond a  
certain point.
Here was my solution for others who might have the problem. Also, I  
hope someone shows me that there is a simpler way.
The Database Model:
class Registration <
2006 Feb 25
0
self referential habtm using join tables
All:
I have been working on making a self-referential habtm relationship
that uses a join model because I want to store info about the
relationship. I have been using two sections from Chad Fowler''s "Rails
Recipes" as a guide, "Self-referential Many-to-Many Relationships" and
"Many to Many Relationships Where the Relationship Itself has Data".
So far I have
2009 May 11
0
updating join table (HMT) with checkbox and extra fields
Hi,
I''ve been breaking my head over this thing with no success. Here is my
table layout -
class User < AR
has_many :memberships
has_many :groups, :through => :memberships
...
class Group < AR
has_many :memberships
has_many :users, :through => :memberships
...
class Membership < AR
  belongs_to :user, :class_name => "User", :foreign_key =>
2005 Nov 16
1
HABTM: deleting records based on attributes
Hello All,
I am new to ROR, and can''t seem to get HABTM to cooperate entirely... 
however I might be abusing it!  Before I try a different strategy I 
thought I''d ask here and see if I''m missing something simple.
So say Projects and Companies are related.  Projects can have multiple 
Companies, and Companies can be on multiple Projects.  But, the same 
Company can also
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.     
2010 Jan 20
0
need help with nested forms and habtm
Hi,
I''m currently stuck with a problem I just can''t find a clever solution
for. I checked every tutorial, issuetracker, API reference I could
find but found nothing to "enlighten" me --> I desperately need your
help :-).
My Question is: is it possible to use nested forms for habtm
associations?
--> Here some more info about what I wanted to do and what failed
2006 Jul 07
3
Newbie Model question (HABTM?)
All,
If I have a table that has several discrete fields that all point to
the same associated field, how do I model it.
Specifically,
If I have a project table that has 2 fields: specifying_company, and
responsible_company.
And one table of associated companies, how do I do the :belongs_to /
:has_many stuff
ie. For a given project company A may be writing the spec, but company
B may be paying
2006 Apr 05
4
Self-referential join creation/deletion and :through
Greetings.
First, this example is just my way of exploring :through.  It probably 
doesn''t need has_many :through, and could just use a standard HABTM 
association.
Here''s the models:
class CourseRequisite < ActiveRecord::Base
  belongs_to :requisite, :class_name => ''Course'', :foreign_key => 
''requisite_id''
  belongs_to :course,
2007 Nov 24
12
orphan habtm rows
HI,
i use models User and Groups connected with many to many association, so 
i have users table, groups and groups_users.
lets say i create one user and one group. next i add a group to user. so 
now my table groups_users has one entry i.e.
group_id | user_id
_________|________
     1    |   1
ok, when i delete both my group and user, above entry is not deleted, 
thus leaving alone without
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many - 
as far as I can tell, if it doesn''t appear at the top of other 
relationship definitions it doesn''t seem to work right. For example:
class Artist < ActiveRecord::Base
  has_and_belongs_to_many :genres
  has_many :albums
  has_many :videos
  has_many :cds
  has_many :collections
end
..works fine
2006 Aug 16
0
Polymorphic Associations and grouping users and projects
Hi all,
In my app I would like to create user groups in my admin. Currently I 
have the following models and associations that facilitate this.
class User < ActiveRecord::Base
  has_many :memberships
  has_many :groups,  :through => :memberships
end
class Membership < ActiveRecord::Base
  belongs_to :group
  belongs_to :user
end
class Group < ActiveRecord::Base
  has_many