ddoherty03
2011-Jun-07 20:42 UTC
Fixtures rejecting reference to ''belongs_to'' association
I have a stock-related rails app, and I want to test the Price model. Each price object represents daily price data for a single Equity, which in turn belongs to a single Issuer. I''ve run the test with the following fixtures and get this error: ============================================== 1) Error: test_the_truth(PriceTest): ActiveRecord::StatementInvalid: PGError: ERROR: column "equity" of relation "prices" does not exist LINE 1: INSERT INTO "prices" ("equity", "dat", "opn", "hgh", "low", ... ^ : INSERT INTO "prices" ("equity", "dat", "opn", "hgh", "low", "cls", "vol", "created_at", "updated_at", "id") VALUES (''sprint_common'', ''2010-01-04'', 3.71, 3.92, 3.7, 3.9, 59299500, ''2011-06-07 19:49:44'', ''2011-06-07 19:49:44'', 1014512129) /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'' =============================================== Here is what the fixtures look like: ==================== prices.yml ===================p_01_04: equity: sprint_common dat: 2010-01-04 opn: 3.71 hgh: 3.92 low: 3.7 cls: 3.9 vol: 59299500 p_01_05: equity: sprint_common dat: 2010-01-05 opn: 3.92 hgh: 4.2 low: 3.9 cls: 4.13 vol: 95552600 ===================== equities.yml ============================sprint_common: rawsym: s sym: S xch: NYSE issuer: sprint earliest: 2005-08-16 latest: 2010-12-31 ====================== issuers.yml ============================sprint: cik: 10830 name: Sprint Nextel Corporation sic: 4813 stinc: KS fy_mo: 12 fy_day: 31 I''ve read the Fixtures document, which indicates that this ought to work. But I''ve also read that having a foreign key somehow keeps fixtures from loading. I have defined a foreign key constraint in one of my migrations from the prices to equities tables. Is it the foreign key that''s causing the problem? If so, is there any work around without deleting the foreign keys? Thanks, -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/elpfUGllemh6V1VK. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Jun-07 20:48 UTC
Re: Fixtures rejecting reference to ''belongs_to'' association
On 7 June 2011 21:42, ddoherty03 <ddoherty03-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a stock-related rails app, and I want to test the Price model. Each > price object represents daily price > data for a single Equity, which in turn belongs to a single Issuer. I''ve > run the test with the following fixtures and get this > error: > ==============================================> 1) Error: > test_the_truth(PriceTest): > ActiveRecord::StatementInvalid: PGError: ERROR: column "equity" of relation > "prices" does not exist > LINE 1: INSERT INTO "prices" ("equity", "dat", "opn", "hgh", "low", ...What do your has_many and belongs_to relationships look like in the models? What columns are present in the tables? Colin> ^ > : INSERT INTO "prices" ("equity", "dat", "opn", "hgh", "low", "cls", "vol", > "created_at", "updated_at", "id") VALUES (''sprint_common'', ''2010-01-04'', > 3.71, 3.92, 3.7, 3.9, 59299500, ''2011-06-07 19:49:44'', ''2011-06-07 > 19:49:44'', 1014512129) > > /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract_adapter.rb:202:in > `rescue in log'' > ===============================================> Here is what the fixtures look like: > ==================== prices.yml ===================> p_01_04: > equity: sprint_common > dat: 2010-01-04 > opn: 3.71 > hgh: 3.92 > low: 3.7 > cls: 3.9 > vol: 59299500 > > p_01_05: > equity: sprint_common > dat: 2010-01-05 > opn: 3.92 > hgh: 4.2 > low: 3.9 > cls: 4.13 > vol: 95552600 > ===================== equities.yml ============================> sprint_common: > rawsym: s > sym: S > xch: NYSE > issuer: sprint > earliest: 2005-08-16 > latest: 2010-12-31 > ====================== issuers.yml ============================> sprint: > cik: 10830 > name: Sprint Nextel Corporation > sic: 4813 > stinc: KS > fy_mo: 12 > fy_day: 31 > > I''ve read the Fixtures document, which indicates that this ought to work. > But I''ve also read that > having a foreign key somehow keeps fixtures from loading. I have defined a > foreign key constraint in > one of my migrations from the prices to equities tables. > Is it the foreign key that''s causing the problem? If so, is there any work > around without deleting the foreign keys? > Thanks, >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ddoherty03
2011-Jun-07 21:00 UTC
Re: Fixtures rejecting reference to ''belongs_to'' association
Colin, ======================== price.rb ========================== class Price < ActiveRecord::Base belongs_to :equities .... end ========================equitiy.rb=========================class Equity < ActiveRecord::Base after_initialize :clean_up after_update :clean_up belongs_to :issuer has_many :prices ... end =======================issuer.rb============================class Issuer < ActiveRecord::Base after_initialize :clean_up after_update :clean_up validates_uniqueness_of :cik has_many :filings has_many :equities has_many :former_names .... end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/d1BTVXhVb0c3QWNK. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Jun-07 21:04 UTC
Re: Fixtures rejecting reference to ''belongs_to'' association
On 7 June 2011 22:00, ddoherty03 <ddoherty03-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Colin, > ======================== price.rb ==========================> class Price < ActiveRecord::Base > belongs_to :equitiesThat should be :equity, singular Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ddoherty03
2011-Jun-07 21:18 UTC
Re: Fixtures rejecting reference to ''belongs_to'' association
Thanks, Colin. That did it. You ''da man. Snow blindness strikes again. Regards, -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/YVlMZFUtRUZkNDhK. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.