I have two models cow and milkman. I am using has_and_belongs_to_many in both models . By mistake i have deleted cows_milkmans table from database. When i use this command i am getting error a = Cow.last a.milkmans # when i fire this command then i am getting error that cows_milkmans table not exist As per my knowledge has_and_belongs_to_many will create third table automatically , no migration is needed. How can get that table ? -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/UST5imVYvwMJ. For more options, visit https://groups.google.com/groups/opt_out.
vijaya sekhar reddy mallidi
2012-Sep-21 10:27 UTC
Re: has_and_belongs_to_many migration problem i am facing
Hi pafahim, When you use HABM association in your models It will not generate the join table automatically. We have to create manually. For your issue try to rollback the join table from database. Thanks & Regards, VIjay On Fri, Sep 21, 2012 at 3:51 PM, Fahim Patel <pafahim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have two models cow and milkman. > I am using has_and_belongs_to_many in both models . > By mistake i have deleted cows_milkmans table from database. > > When i use this command i am getting error > a = Cow.last > a.milkmans # when i fire this command then i am getting error that > cows_milkmans table not exist > > As per my knowledge has_and_belongs_to_many will create third table > automatically , no migration is needed. > > How can get that table ? > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/UST5imVYvwMJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.
Fahim Patel
2012-Sep-21 11:07 UTC
Re: has_and_belongs_to_many migration problem i am facing
No man ... i just use HABM in models and when i fire command in console at that point third table is created. And i do nothing manually.. On Friday, September 21, 2012 3:51:41 PM UTC+5:30, Fahim Patel wrote:> > I have two models cow and milkman. > I am using has_and_belongs_to_many in both models . > By mistake i have deleted cows_milkmans table from database. > > When i use this command i am getting error > a = Cow.last > a.milkmans # when i fire this command then i am getting error that > cows_milkmans table not exist > > As per my knowledge has_and_belongs_to_many will create third table > automatically , no migration is needed. > > How can get that table ? > >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tPh97NyF83oJ. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Sep-22 10:00 UTC
Re: Re: has_and_belongs_to_many migration problem i am facing
On Fri, Sep 21, 2012 at 9:07 PM, Fahim Patel <pafahim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No man ... > i just use HABM in models and when i fire command in console at that > point third table is created. > And i do nothing manually.. >Hi! I don''t use habtm so I''m not familiar with how it work in core. But reading from http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don’t need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you’ll need to remember to create the joining table in the database). You should use has_many :through if you need validations, callbacks, or extra attributes on the join model. So I guess you need to create that table in the database manually.> > > On Friday, September 21, 2012 3:51:41 PM UTC+5:30, Fahim Patel wrote: >> >> I have two models cow and milkman. >> I am using has_and_belongs_to_many in both models . >> By mistake i have deleted cows_milkmans table from database. >> >> When i use this command i am getting error >> a = Cow.last >> a.milkmans # when i fire this command then i am getting error that >> cows_milkmans table not exist >> >> As per my knowledge has_and_belongs_**to_many will create third table >> automatically , no migration is needed. >> >> How can get that table ? >> >> -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/tPh97NyF83oJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Dave Aronson
2012-Sep-22 16:38 UTC
Re: Re: has_and_belongs_to_many migration problem i am facing
On Sat, Sep 22, 2012 at 6:00 AM, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> reading from > http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association > > The simplest rule of thumb is that you should set up a has_many :through > relationship if you need to work with the relationship model as an > independent entity. If you don’t need to do anything with the relationship > model, it may be simpler to set up a has_and_belongs_to_many relationship > (though you’ll need to remember to create the joining table in the > database). > > You should use has_many :through if you need validations, callbacks, or > extra attributes on the join model.Also, I haven''t had to do it myself, but I''ve heard that retrofitting a habtm setup to use hmt, after discovering a need for any of the above, can be a royal pain in the proverbial posterior. So, I usually just ignore habtm, and use hmt for all such joins. -Dave -- Dave Aronson, Available Secret-Cleared Ruby/Rails Freelancer (VA/DC/Remote); see www.DaveAronson.com, www.Codosaur.us, and www.Dare2XL.com for more info. -- 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 https://groups.google.com/groups/opt_out.