Displaying 20 results from an estimated 461 matches for "class_names".
Did you mean:
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
2005 Aug 16
1
Defining model classes for enumerations
I have several tables for enumerations. They all have the same content:
id, name, position. I''d like to avoid the tedious work of defining 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|
2006 Mar 31
3
Complex Through Statement
Quick Overview:
I have an ''Employee'', some ''Merchants'' and some ''Products''. A
''Merchant'' has many ''Products''. An ''Employee'' has multiple ''Merchants'',
depending on their relationship. For example, the Employee may be the
enrollment contact for one merchant and the
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,
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
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
I thought I had this nailed but.. now I''m seeing spots..
I''ve included my models below, feel free to ignore them. I''m really
just after an example that works. I couldnt find one on the wiki...
which is fair enough considering Ricks patch:
http://dev.rubyonrails.org/changeset/4022 that fixed them only went
through 5 days ago..
Cheers
-henster
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 Jan 09
3
Include with two references of one model of the same table
Hey guys,
I just came across this oddity, not sure what to make of it yet, but
I think it might be incorrect behavior. When doing a @inst.find(:all,
:include => ["hometeam", "awayteam"] ...) hometeam and awayteam are two
references from a belongs_to that is of the same model and of the same
table. I will get a pgerror stating that "matches", which is
2006 Mar 15
1
Through method problems with custom foreign_keys
A person has a many company_branches and
A company_branch has many people.
This join is represented using a "contacts" table.
I am using a legacy schema so i am forced into using non-standard rails
primary keys. I am using the new through relationship in rails 1.1.
p=Person.find(1)
b=p.company_branches # gives this error:
ActiveRecord::StatementInvalid: OCIError: ORA-00904:
2009 Dec 26
3
Does :class_name for belongs_to have to be a string and why?
Seemingly, when I use a symbol, 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
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(1) not null,
)
--- relations ---
f = friend
r = request to
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
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",
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
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
class Person < ActiveRecord::Base
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,