This was a known problem addressed by
http://dev.rubyonrails.com/ticket/533. Fix is already present in edge
rails, so if changing DDL is not an option and you cannot live without
syntactic sugar coming from dynamic finders like find_by* you could
just check out Rails from svn and use it instead of gem version.
Please see http://wiki.rubyonrails.com/rails/show/EdgeRails for
detailed instructions.
Cheers,
Zsombor
On 6/15/05, Peter Fitzgibbons
<Peter.Fitzgibbons-p2lxMnUesd41y/cD6r8xzl6hYfS7NtTn@public.gmane.org>
wrote:>
>
> Hello All,
>
> I''m having trouble with find_by''s...they seem to not
exist in my model at
> runtime?
>
> Rails 0.12.1 AR 1.10.0
>
> Below is the DDL for table Project. This is a legacy system and data
> structure... Modifying existing columns would be very painful.
>
> Below after DDL is the model Project.rb
> In IRB:
> C:\ruby\dev\pm>ruby script\console
> Loading development environment.
> irb(main):001:0> p = Project.find_by_projectactive(1)
> NoMethodError: undefined method `find_by_projectactive'' for
Project:Class
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `method_missing''
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `each''
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `method_missing''
> from (irb):1
> irb(main):002:0> p = Project.find_by_ProjectActive(1)
> NoMethodError: undefined method `find_by_ProjectActive'' for
Project:Class
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:800:in
> `method_missing''
> from (irb):2
> irb(main):003:0> p = Project.find_by_projectactive(1)
> NoMethodError: undefined method `find_by_projectactive'' for
Project:Class
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `method_missing''
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `each''
> from
>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.10.1/lib/active_record/base.rb:788:in
> `method_missing''
> from (irb):3
> irb(main):004:0>
>
> Advice anyone?
>
> Thanks in advance!
>
>
>
> Peter J. Fitzgibbons
> Applications Manager
> Lakewood Homes - "The American Dream Builder"(r)
> Peter.Fitzgibbons-STCS76aLmhk1y/cD6r8xzl6hYfS7NtTn@public.gmane.org
> (847) 884-8800
>
> CREATE TABLE [Project] (
> [ProjectID] [int] IDENTITY (1, 1) NOT NULL ,
> [CompanyID] [int] NOT NULL ,
> [ProjectNumber] [nvarchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS
> NOT NULL CONSTRAINT [DF_Project_ProjectNumber] DEFAULT (null),
>
> [ProjectDescription] [nvarchar] (35) COLLATE
> SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT
> [DF_Project_ProjectDescription] DEFAULT (null),
>
> [StartDate] [datetime] NULL CONSTRAINT [DF_Project_StartDate]
> DEFAULT (null),
> [ProjectEstimatedCompletionDate] [datetime] NULL
> CONSTRAINT [DF_Project_ProjectEstimatedCompletionDate]
> DEFAULT (null),
>
> [NoLotsUnits] [int] NOT NULL CONSTRAINT [DF_Project_NoLotsUnits]
> DEFAULT (0),
> [ContactName] [nvarchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ContactName] DEFAULT (null),
>
> [AddressLine1] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine1] DEFAULT (null),
>
> [AddressLine2] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine2] DEFAULT (null),
>
> [AddressLine3] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine3] DEFAULT (null),
>
> [AddressLine4] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine4] DEFAULT (null),
>
> [ContactPhone] [nvarchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ContactPhone] DEFAULT (null),
>
> [CityCode] [nvarchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
> CONSTRAINT [DF_Project_CityCode] DEFAULT (null),
>
> [ProjectType] [int] NOT NULL CONSTRAINT [DF_Project_ProjectTypeID]
> DEFAULT (0),
> [ProjectActive] [bit] NOT NULL CONSTRAINT
[DF_Project_ProjectActive]
> DEFAULT (0),
> [ProjectCity] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ProjectCity] DEFAULT (null),
>
> [Directions] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_Directions] DEFAULT (null),
>
> [House_Cost_Inflation] [money] NOT NULL CONSTRAINT
> [DF_Project_House_Cost_Inflation] DEFAULT (0),
> [House_Cost_Inflation_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_House_Cost_Inflation_Percent] DEFAULT (0),
>
> [Cost_of_Incentive] [money] NOT NULL CONSTRAINT
> [DF_Project_Cost_of_Incentive] DEFAULT (0),
> [Indirect_Overhead_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Indirect_Overhead_Percent] DEFAULT (0),
> [Service_Allocation_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Service_Allocation_Percent] DEFAULT (0),
> [Selling_Expenses_Fixed_Percent] [real] NOT NULL
> CONSTRAINT [DF_Project_Selling_Expenses_Fixed_Percent]
> DEFAULT (0),
>
> [Selling_Expenses_Variable_Percent] [real] NOT NULL
> CONSTRAINT [DF_Project_Selling_Expenses_Variable_Percent]
> DEFAULT (0),
>
> [Model_Area_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Model_Area_Percent] DEFAULT (0),
> [Advertising_Media_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Advertising_Media_Percent] DEFAULT (0),
> [Closing_Cost_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Closing_Cost_Percent] DEFAULT (0),
> [Const_Loan_Interest_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Const_Loan_Interest_Percent] DEFAULT (0),
> [Investor_Fees_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Investor_Fees_Percent] DEFAULT (0),
> [G_and_A_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_G_and_A_Percent] DEFAULT (0),
> [Recommended_Change] [money] NOT NULL CONSTRAINT
> [DF_Project_Recommended_Change] DEFAULT (0),
> [Total_Lot_Cost] [money] NOT NULL CONSTRAINT [DF_Project_Site_Cost]
> DEFAULT (0),
> [GEACLink] [bit] NOT NULL CONSTRAINT [DF_Project_GEACLink] DEFAULT
> (0),
> [CompanyCode] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS
> NOT NULL ,
> [BidsResponseDueDate] [datetime] NULL ,
> [UIUpdated] [bit] NULL CONSTRAINT
> [DF__Project__UIUpdat__336AA144] DEFAULT (1),
> [DataLoadUpdated] [bit] NULL CONSTRAINT
> [DF__Project__DataLoa__345EC57D] DEFAULT (0),
> [GEACWrite] [bit] NOT NULL CONSTRAINT [DF_Project_GEACWrite]
DEFAULT
> (0),
> [CFTProjectID] [int] NULL ,
> [FullBasementCategoryCode] [nvarchar] (5) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [FullBasementOptionCode] [nchar] (3) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [DefaultPOHold] [bit] NULL ,
> [salesapp] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
> [sales_community_id] [varchar] (50) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> CONSTRAINT [PROJECT_PK] PRIMARY KEY CLUSTERED
> (
> [ProjectID]
> ) WITH FILLFACTOR = 90 ON [PRIMARY] ,
> CONSTRAINT [IX_ProjectNumber] UNIQUE NONCLUSTERED
> (
> [CompanyID],
> [ProjectNumber]
> ) WITH FILLFACTOR = 90 ON [PRIMARY] ,
> CONSTRAINT [PROJECT_COMPANY_FK] FOREIGN KEY
> (
> [CompanyID]
> ) REFERENCES [Company] (
> [CompanyID]
> )
> ) ON [PRIMARY]
> GO
>
> CREATE TABLE [Project] (
> [ProjectID] [int] IDENTITY (1, 1) NOT NULL ,
> [CompanyID] [int] NOT NULL ,
> [ProjectNumber] [nvarchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS
> NOT NULL CONSTRAINT [DF_Project_ProjectNumber] DEFAULT (null),
>
> [ProjectDescription] [nvarchar] (35) COLLATE
> SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT
> [DF_Project_ProjectDescription] DEFAULT (null),
>
> [StartDate] [datetime] NULL CONSTRAINT [DF_Project_StartDate]
> DEFAULT (null),
> [ProjectEstimatedCompletionDate] [datetime] NULL
> CONSTRAINT [DF_Project_ProjectEstimatedCompletionDate]
> DEFAULT (null),
>
> [NoLotsUnits] [int] NOT NULL CONSTRAINT [DF_Project_NoLotsUnits]
> DEFAULT (0),
> [ContactName] [nvarchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ContactName] DEFAULT (null),
>
> [AddressLine1] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine1] DEFAULT (null),
>
> [AddressLine2] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine2] DEFAULT (null),
>
> [AddressLine3] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine3] DEFAULT (null),
>
> [AddressLine4] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_AddressLine4] DEFAULT (null),
>
> [ContactPhone] [nvarchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ContactPhone] DEFAULT (null),
>
> [CityCode] [nvarchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
> CONSTRAINT [DF_Project_CityCode] DEFAULT (null),
>
> [ProjectType] [int] NOT NULL CONSTRAINT [DF_Project_ProjectTypeID]
> DEFAULT (0),
> [ProjectActive] [bit] NOT NULL CONSTRAINT
[DF_Project_ProjectActive]
> DEFAULT (0),
> [ProjectCity] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_ProjectCity] DEFAULT (null),
>
> [Directions] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL CONSTRAINT [DF_Project_Directions] DEFAULT (null),
>
> [House_Cost_Inflation] [money] NOT NULL CONSTRAINT
> [DF_Project_House_Cost_Inflation] DEFAULT (0),
> [House_Cost_Inflation_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_House_Cost_Inflation_Percent] DEFAULT (0),
>
> [Cost_of_Incentive] [money] NOT NULL CONSTRAINT
> [DF_Project_Cost_of_Incentive] DEFAULT (0),
> [Indirect_Overhead_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Indirect_Overhead_Percent] DEFAULT (0),
> [Service_Allocation_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Service_Allocation_Percent] DEFAULT (0),
> [Selling_Expenses_Fixed_Percent] [real] NOT NULL
> CONSTRAINT [DF_Project_Selling_Expenses_Fixed_Percent]
> DEFAULT (0),
>
> [Selling_Expenses_Variable_Percent] [real] NOT NULL
> CONSTRAINT [DF_Project_Selling_Expenses_Variable_Percent]
> DEFAULT (0),
>
> [Model_Area_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Model_Area_Percent] DEFAULT (0),
> [Advertising_Media_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Advertising_Media_Percent] DEFAULT (0),
> [Closing_Cost_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Closing_Cost_Percent] DEFAULT (0),
> [Const_Loan_Interest_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Const_Loan_Interest_Percent] DEFAULT (0),
> [Investor_Fees_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_Investor_Fees_Percent] DEFAULT (0),
> [G_and_A_Percent] [real] NOT NULL CONSTRAINT
> [DF_Project_G_and_A_Percent] DEFAULT (0),
> [Recommended_Change] [money] NOT NULL CONSTRAINT
> [DF_Project_Recommended_Change] DEFAULT (0),
> [Total_Lot_Cost] [money] NOT NULL CONSTRAINT [DF_Project_Site_Cost]
> DEFAULT (0),
> [GEACLink] [bit] NOT NULL CONSTRAINT [DF_Project_GEACLink] DEFAULT
> (0),
> [CompanyCode] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS
> NOT NULL ,
> [BidsResponseDueDate] [datetime] NULL ,
> [UIUpdated] [bit] NULL CONSTRAINT
> [DF__Project__UIUpdat__336AA144] DEFAULT (1),
> [DataLoadUpdated] [bit] NULL CONSTRAINT
> [DF__Project__DataLoa__345EC57D] DEFAULT (0),
> [GEACWrite] [bit] NOT NULL CONSTRAINT [DF_Project_GEACWrite]
DEFAULT
> (0),
> [CFTProjectID] [int] NULL ,
> [FullBasementCategoryCode] [nvarchar] (5) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [FullBasementOptionCode] [nchar] (3) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [DefaultPOHold] [bit] NULL ,
> [salesapp] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
> [sales_community_id] [varchar] (50) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> CONSTRAINT [PROJECT_PK] PRIMARY KEY CLUSTERED
> (
> [ProjectID]
> ) WITH FILLFACTOR = 90 ON [PRIMARY] ,
> CONSTRAINT [IX_ProjectNumber] UNIQUE NONCLUSTERED
> (
> [CompanyID],
> [ProjectNumber]
> ) WITH FILLFACTOR = 90 ON [PRIMARY] ,
> CONSTRAINT [PROJECT_COMPANY_FK] FOREIGN KEY
> (
> [CompanyID]
> ) REFERENCES [Company] (
> [CompanyID]
> )
> ) ON [PRIMARY]
> GO
>
> class Project < ActiveRecord::Base
> set_table_name "Project"
> set_primary_key "ProjectID"
>
> belongs_to :sales_community
>
> has_many :model, :foreign_key=>"ProjectID",
:order=>"ModelCode"
>
> end
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
--
http://deezsombor.blogspot.com