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) 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-/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.
On 26 March 2010 10:19, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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) > > > 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 ?I _think_, though I may be corrected, that when you do create it allows the database to set the id. If you provide one yourself it is ignored. The database has allocated the next in sequence even though earlier ones have been removed. 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.
hi, can u fill the database with the current_user? i want / need to fill a few tables after the user got activated, but the tables i need to fill have to have the user_id in it...is that possible? thx On Fri, Mar 26, 2010 at 6:39 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 March 2010 10:19, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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) > > > > > > 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 ? > > I _think_, though I may be corrected, that when you do create it > allows the database to set the id. If you provide one yourself it is > ignored. The database has allocated the next in sequence even though > earlier ones have been removed. > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/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.
On 26 March 2010 13:16, tom <tomabroad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, can u fill the database with the current_user? > > i want / need to fill a few tables after the user got activated, but the > tables i need to fill have to have the user_id in it...is that possible?I don''t understand what you mean. Setting a field user_id is not a problem, it is just the primary key id field that is a problem. Colin> > thx > > > On Fri, Mar 26, 2010 at 6:39 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 26 March 2010 10:19, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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) >> > >> > >> > 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 ? >> >> I _think_, though I may be corrected, that when you do create it >> allows the database to set the id. If you provide one yourself it is >> ignored. The database has allocated the next in sequence even though >> earlier ones have been removed. >> >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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-/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. >-- 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.
Hi So my question is how can I ensure that even after running rake db:seed (rake db:seed_fu) a number of times my primary key ie, id here, does not get modified? Should I need to write an update_id function again? Thanks 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-/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.
On Fri, Mar 26, 2010 at 3:19 AM, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/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.
On 29 March 2010 05:42, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > So my question is how can I ensure that even after running rake > db:seed (rake db:seed_fu) a number of times my primary key ie, id here, > does not get modified? Should I need to write an update_id function > again?If you really need the id to be pre-defined (though why you need to do this I do not know, it is generally a bad idea) then in your seed code you could check whether a record of that id already exists and if it does then update it rather than re-creating it. 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.
Hi Thanks for your reply> 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.What I tried is as my first post. Now just as a test a I did like State.destroy_all State.create(:id => 1,:name => "Alabama", :abbr => ''AL'',:fips => ''01'', :country_id => 1) But after this step whenever I do rake db:seed_fu I dont get what I expected for the id fields. I expect id to be generated like 1,2,3....> If you really need the id to be pre-defined (though why you need to do > this I do not know, it is generally a bad idea)Why I need the id to be predefined means suppose at a later stage if already that id may e saved to a number of tables as foreign key. But suppose if execute rake db:seed_fu then if the id changed to 5,6,7 instead of 1,2,3 the total solution may be a big fail So when I checked the way which I mentioned in my first post accidently I noticed this. Then post a message to a get a clarification since I dont know where the fault is I think one more thing to ensure the ids are the values that I expected is, after creation call a function like @country.update_id_to(1) ..... Thanks 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-/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.