search for: has_many

Displaying 20 results from an estimated 2042 matches for "has_many".

2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will fail to generate proper SQL class StudentSemesterRecord < ActiveRecord::Base belongs_to :semester has_many :discipline_records, :through => :semester end class Semester < ActiveRecord::Base has_many :student_semester_records has_many :discipline_records end clas...
2006 Jul 23
4
has_many AND has_many :through ?
Hi, I am working on a scheduling app and I have a perpelextion (new word). I am wondering if the problem is my data model I have Users. Users can create Events. Users can be invited to Events created by other Users. So... user.rb class User < ActiveRecord::Base has_many :invitations # invitations to other users'' events has_many :events, :through => :invitations # all events the user is invited to #HERE IS THE PROBLEM has_many :events # the events that the user is the owner of end event.rb class Event < ActiveRecord::Base has_many :invitat...
2006 Mar 30
5
Has_many :through problems -- please help
I''m having a lot of trouble with has_many, :through and could really use some assistance. I''ve got a User and Group class. Users can subscribe to groups, and groups should know who''s subscribed. I''ve got a join table (group_subscriptions) with group_id, user_id, and it''s own id element. Users h...
2006 Aug 03
12
More than one has_many :through association between the same 2 models
I wonder if you can have more than one has_many :through association between 2 models. For example... I have a model Teacher and a model Class Now, 1 Teacher works in many Classes, right?. So I need a join model like class Work < ActiveRecord::Base belongs_to :teacher belongs_to :class end But I also would l...
2006 Jul 04
2
has_many working correctly only on reload!
I have this code that is using svn externals with rails EDGE working fine for the past couple of months. A couple of days ago, this code died. Even after deleting vendor/rails, this code doesnt work: class Tag < ActiveRecord::Base has_many :taggings has_many :events, :through => :taggings has_many :users, :through => :taggings end class User < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password has_many :events has_many :posts has_many :taggings has_many :tags, :throug...
2006 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
I am having a problem with doing a :through that goes back to the same table. The following are my two classes: >>>>> class User < ActiveRecord::Base has_many :spanks has_many :spanked, :through => :spanks, :source => :spanked_user has_many :was_spanked_by, :through => :spanks, :source => :user end class Spank < ActiveRecord::Base belongs_to :spanker, :class_name => "User", :foreign_key => "user_id" belon...
2006 Feb 11
6
Rails Edge, has_many :through in searches
I have two tables, a Projects table and a Clients table. It''s basically a HABTM relationship, but I have additional project/ client-specific information in the join table. I''m trying to use the new has_many :through method to join these. It works fine when displaying records, but when I try to search, I''m having this problem: When I used a HABTM model to search the project list for project and client names, this worked fine: @projects = Project.find(:all, :include => [:client], :cond...
2006 Mar 31
3
Complex Through Statement
...;Employee'' has multiple ''Merchants'', depending on their relationship. For example, the Employee may be the enrollment contact for one merchant and the support contact for another. Therefore, my Employee class looks like this: class Employee < ActiveRecord::Base has_many :enrollment_merchants, :class_name => "Merchant", :foreign_key => :enrollment_employee_id has_many :support_merchants, :class_name => "Merchant", :foreign_key => :support_employee_id end And my Merchant class looks like this: class Merchant < ActiveRecord::...
2010 Jan 27
2
has_many, through with nested models?
First the data model: class Forum < ActiveRecord::Base has_many :topics, :dependent => :destroy, :order => ''created_at desc'' end class User < ActiveRecord::Base has_many :topics, :dependent => :destroy has_many :comments, :dependent => :destroy has_many :replies, :dependent => :destroy end class Topic < ActiveReco...
2006 May 25
5
Model Structure Advise
...rting to build a simple (?!) FAQ system, and I''d like some advice on setting up the model relationships. I was going to go with a simple system of a Category table and a FAQ table (holding questions and answers) - where one FAQ belongs to one category. That''s all nice - a simple has_many / belongs_to relationship. Then I decided to add another level - Area. So I could make the system work for a wider audience (IT area has it''s own categories and FAQ''s, Sales area has it''s own categories and FAQ''s, etc.) I''m not sure how the best way to...
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations, what is the ''best'' way to handle validations? As an example: class Student < ActiveRecord::Base # some attrbutes like # :name # :grade # relationships has_many :students_assignment, :dependent => :destroy has_many :assignments, :...
2006 Mar 29
4
:through alternate
I''d like to use :through to create a web of associations like: class Thing < ActiveRecord::Base has_many :child_things, :through => :thing_thing has_many :parent_things, :through => :thing_thing, :some_other_option? end class ThingThing < ActiveRecord::Base belongs_to :thing belongs_to :child_thing, :class_name => ''Thing'', :foreign_key => ''child_thing_...
2007 Nov 24
12
orphan habtm rows
...ove entry is not deleted, thus leaving alone without any reason.. its just an orphan record, which is useless. is there any parameter in rails that removes such records ? i dont want to have too many useless records at all. btw. its not :dependant => :destroy parameter, this applies only to has_many association... regards. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscr...
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 => ''model_name'' Should this work?...
2006 Aug 02
2
Self-Referential has_many :through
Hello all. I am trying to create a self-referential has_many :through. I used the following site as a guide http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through but it still doesn''t appear to be working. I have two models. Person and Relationship. A person has many contacts (Which is another person) through relationships...
2011 Jan 15
3
has_many :through with Single Table inheritance
I have the following model structure setup. class User < ActiveRecord::Base end class Parent < User has_many :relationships has_many :children, :class_name => "Student", :through => :relationships, :conditions => "related_as = ''parent''" end class Student < User has_many :relationships has_many :par...
2006 May 28
7
Self-referential has_many :through relationship
Hi, I have a self-referential has_many :through relationship setup to track relationships between users. Basically relationships are modeled as a join table with an extra column ''relation''. create table relationships ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(...
2010 Mar 01
3
has_many models in a form
Hi, guys. There are four models in the program, A has_many B through C, B has_many A through C, A has_many D, D belongs_to A. I have a form to create A. Inspired by Ryan Bates'' railscasts I was able to create A and D in the same form, and link A to B(created beforehand) through C in the same form as well. Is it possible to create A and B in the...
2005 Dec 26
2
Dynamic order on has_many relationship?
I was wondering if it''s possible to some how control the :order given on a has_many depending on another attribute? Or do I need to just create multiple has_many relationships pointing to the same table but with different orders and then select which one I use in the controller instead? e.g class Category < AR::B has_many :products, :order => //something magical?// e...
2006 May 12
1
can I fake has_one :through?
I''m having a difficult time wrapping my head around a set of models and their associations and seeing how they map into Rails. I''ll try to lay out my problem using the has_many and belongs_to structures. I have a RuleSpace, a Rule, and a Subject. A RuleSpace has_many Rules A RulesSpace has_many Subjects through Rules A Rule belongs_to (many) RuleSpaces A Rule has_many Subjects A Subject has_one Rule A Subject has_one RuleSpace So given a single Subject I should be a...