On Fri, Mar 26, 2010 at 3:19 AM, Tom Mac <lists@ruby-forum.com> wrote:
Hi
I am using seed_fu to seed initial data to tables
(http://github.com/mbleigh/seed-fu) . And in db/fixtures/state.rb
I have values like (I am filling only two data for simplicity)
State.seed_many(:name, :abbr,:fips,:country_id, [
{ :name => "Alberta", :abbr => 'AB',:fips => '01', :country_id =>
2 },
{ :name => "Alaska", :abbr => 'AK',:fips => '02', :country_id => 1
}
])
It works and when I do select * from states; I get result as
+-----+------+-----------------------+------+------------+
| id | abbr | name | fips | country_id |
+-----+------+-----------------------+------+------------+
| 1 | AB | Alberta | 01 | 2 |
| 2 | AK | Alaska | 02 | 1 |
But now I modified state.rb as
State.seed_many(:name, :abbr,:fips,:country_id, [
{ :name => "Alberta", :abbr => 'AB',:fips => '01', :country_id =>
2 },
{ :name => "Alaska", :abbr => 'AK',:fips => '02', :country_id => 1
}
])
State.destroy_all
State.create(:id => 1,:name => "Alabama", :abbr => 'AL',:fips => '01',
:country_id => 1)
Tom, you shouldn't be setting the value of the :id field because the database
will ignore your setting and assign the next unique identifier automatically.
Could you explain what you're trying to do in a step by step scenario? This
may helper others on the mailing list to better assist you.
-Conrad
And now when I do select * from states; I get unexpected result as
+-----+------+-----------------------+------+------------+
| id | abbr | name | fips | country_id |
+-----+------+-----------------------+------+------------+
| 5 | AL | Alabama | 01 | 1 |
What I expect was id=1 But I got id as 5 . Why this ?
Thanks in advance
Tom
--
Posted via http://www.ruby-forum.com/.
--
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.
--
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.
No comments:
Post a Comment