Re: [Rails] Fixtures rejecting reference to 'belongs_to' association
On 7 June 2011 21:42, ddoherty03 <ddoherty03@gmail.com> 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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home