search for: class_name

Displaying 20 results from an estimated 461 matches for "class_name".

2006 Apr 05
9
Is eval the only way?
Hi, I''m trying to write some methods which use a parameter to represent a Class name. A very simplistic example: def foo(class_name, conditions) x = class_name.find(:all, :conditions => "#{conditions}") end Unfortunately, this does not work. The only way around this problem that I can think of is to use eval: def foo(class_name, conditions) x = eval "#{class_name}.find(:all, :conditions => \"...
2005 Aug 16
1
Defining model classes for enumerations
...efining a class for each one explicitly. Not least, in order to avoid clutter in the model directory. Here''s what I''ve come up with: class EnumRecord < ActiveRecord::Base def self.define_enums(*enums) enums.each do |spec| if spec.kind_of?(Hash) class_name = spec[:class_name].to_s raise ArgumentError, ''An enum specification must contain a :class_name'' if class_name.empty? order = spec[:order] || ''position'' table_name = spec[:table_name] || class_name else class_name...
2006 Mar 31
3
Complex Through Statement
...''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::Base belongs_to :enrollment_empl...
2006 Nov 02
4
Still Having Problems With :through When Going To Same Table... Help... please :-(
...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" belongs_to :spankee, :class_name => "User", :foreign_key => "spanked_user_id" end db_table:spanks id | user_id | spanked_user_id | created_at | updated_at >>>>> I want to be able to make sta...
2008 Jul 15
9
Beginner Question.
I''m just getting into RoR, coming from a long PHP background. So far I LOVE IT! I''m hitting a roadblock with updating my mysql database. For simplicities sake, I have 2 tables and here are the relevant columns. Table Users id name email Table Issues id createdby assignedto reportedby In my models I have everything mapped properly I believe. When I try to update the
2006 Feb 14
6
Multiple associations to the same class
Hi, I cannot seem to create associations like this: class Project < ActiveRecord::Base belongs_to :manager, :class_name => ''User'', :foreign_key => ''manager'' belongs_to :liaison, :class_name => ''User'', :foreign_key => ''liaison'' end p = Project.new p.manager => 1 trying to retrieve associated objects doesn''t work and I...
2008 Jun 13
6
Newbie question on has_many
I have two classes: a Widget and a User. The User has an id that is referenced in two places on the Widget: owner_id and operator_id. How should I structure that reference for has_many? Thanks folks - I appreciate any help on this. --David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2006 Mar 29
3
Self-referential many-many joins with :through
...is fair enough considering Ricks patch: http://dev.rubyonrails.org/changeset/4022 that fixed them only went through 5 days ago.. Cheers -henster *********************************************************************************** class Topic < ActiveRecord::Base has_many :item_collection, :class_name => "Grouping", :foreign_key => "item_id" has_many :group_collection, :class_name => "Grouping", :foreign_key => "group_id" has_many :groups, :through => :group_colletion has_many :items, :through => :item_collection end ********...
2006 Jul 07
3
Newbie Model question (HABTM?)
...es, 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 the bill. For another project it is possible the arrangement is reverse. I''m guessing this is a HABTM situation, but how do I do the :foreign_key and :class_name setup. Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century
2006 Jan 09
3
Include with two references of one model of the same table
...guously referenced. The SQL spit out showed only one select on "matches" where I think should be two selects on two aliases of "matches". Heres some code below to better understand what I''m talking about. class Match < ActiveRecord::Base belongs_to :hometeam, :class_name => "TeamsSeason", :foreign_key => "hometeam_id" belongs_to :awayteam, :class_name => "TeamsSeason", :foreign_key => "awayteam_id" end class TeamsSeason < ActiveRecord::Base has_many :hometeam, :class_name => "Match", :foreig...
2006 Mar 15
1
Through method problems with custom foreign_keys
..."contacts.company_branch_id" does not exist, it should be "contacts.com_branch_id" Here are the models: class Person < ActiveRecord::Base set_primary_key "person_id" has_many :contacts, :foreign_key=>"person_person_id", :class_name=>"Contact" has_many :company_branches, :through=>:contacts, :foreign_key=>"com_branch_id" end class CompanyBranch < ActiveRecord::Base set_primary_key "branch_id" belongs_to :company, :foreign_key=>"...
2009 Dec 26
3
Does :class_name for belongs_to have to be a string and why?
...ol, I get an ActiveRecord error stating ''Can''t convert symbol into String.'' Why can''t I use a symbol here? Possibly this is a deeper misunderstanding of symbols in general on my part. #ActiveRecord error class Book < ActiveRecord::Base belongs_to :author, :class_name => :Person, :foreign_key => :author_id end #works class Book < ActiveRecord::Base belongs_to :author, :class_name => "Person", :foreign_key => :author_id end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" gr...
2006 May 28
7
Self-referential has_many :through relationship
...s ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(1) not null, ) --- relations --- f = friend r = request to be a friend b = blocked My models look like this: class Relationship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => ''User'', :foreign_key => ''friend_id'' end class User < ActiveRecord::Base has_many :relationships has_many :friendships, :class_name => ''Relationship'', :foreign_key => ''user_id'', :conditions => "re...
2005 Dec 14
5
belongs_to and multiple foreign keys
Hi all, I''m confused about how I''m supposed to specify a belongs_to relationship when the table includes multiple columns that reference the same parent table. In my case I have a "schedules" table with "opened_by" and "closed_by" columns, that both reference the "users" table. In theory, they can be two different user ids. table
2005 Apr 27
4
has_many syntax
Hi all, I have the following inside of an AR class definition: relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql) relationships.each do |relationship| has_many RelatedItems, :class_name => relationship[''RelatedClass''], :foreign_key => relationship[''ForeignKey''] end This kind of works, but how can I assign the name of the relationships? my_relationships_sql retrieves a field called "RelationshipName", and what I would like to do...
2009 Jul 29
5
[newbie] double relationships in database
I have the following tables teams id :string name :string and matches id: home_team :team_id visitor_team :team_id how can I reflect that kind of relationship in a RoR model? thanks and keep up the good work.
2006 Oct 22
3
Keeping DRY - I like a simple life!
Hi, I''m new to Ruby and Rails and I would be very grateful for some advice. I''ve got the following code. class Foo < ActiveRecord::Base include Versionable # Some methods to handle my versioned objects has_many :versions, :class_name => "FooVersion", :foreign_key => "parent_id" belongs_to :curr, :class_name => "FooVersion", :foreign_key => "current_id" belongs_to :unapproved, :class_name => "FooVersion", :foreign_key => "unapproved_id" end I...
2006 Mar 07
13
Active Record - Can''t figure out relationship.
I have the following two tables: create table teams ( id int not null auto_increment, short_name varchar(12) not null, long_name varchar(50) not null, logo varchar(20) not null, primary key (id) ); create table rounds ( id int not null auto_increment, home_team_id int not null, away_team_id int
2006 Aug 02
2
Self-Referential has_many :through
...ass Person < ActiveRecord::Base has_many :relationship has_many :contacts, :through => :relationship end end class Relationship < ActiveRecord::Base belongs_to :person, :foreign_key => "person_id" belongs_to :contact, :foreign_key => "contact_id", :class_name => "Person" end If I use the code as above then while the relationships appear in the view the only "Contact" that appears is the Person I am currently looking at (So the Person "Person A" lists "Person A" as a contact). If, on the other hand I do the...
2006 Mar 07
6
fcgi dispatcher crashing
I''m trying to set deploy an app on apache2 with the fcgid module, but can''t seem to get anywhere. Things work fine with cgi, but when i switch to fcgi, i''m stuck with a ''503: Service Temporarily Unavailable''. There''s no error being logged anywhere, afaik. Trying to run dispatch.fcgi from the shell doesn''t work either. It bombs out,