How can I delete category and set all recipes linked to that category to "no category"? The tutorial at O''Reilly says nothing about that... -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, you''ll simply have to change On 5/23/07, Marko <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > How can I delete category and set all recipes linked to that category to > "no category"? > > The tutorial at O''Reilly says nothing about that... > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Conrad Taylor wrote:> Hi, you''ll simply have to change:-) So do I have to make a new Category with name ''no category'' and than link all recipes to new category? What if I have Author of recipe... table Authors with fields: id first_name last_name city state street zip phone Now how do I set "no author" here? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i believe what you want to do is: Recipe < AR::Base belongs_to :category belongs_to :author end Category < AR::Base has_many :recipes, :dependent => :nullify end Author < AR::Base has_many :recipes, :dependent => :nullify end what this does is if you delete/destroy a category or author, the recipe''s foreign keys will be set to null, which in effect says that the recipe has no category or author, depending on which you deleted/destroyed. On 5/23/07, Marko <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Conrad Taylor wrote: > > Hi, you''ll simply have to change > > :-) So do I have to make a new Category with name ''no category'' and than > link all recipes to new category? > > What if I have Author of recipe... > > table Authors with fields: > > id > first_name > last_name > city > state > street > zip > phone > > Now how do I set "no author" here? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what i did was make a category titled category and make it so its not editable or deletable by the user. that way, there will be at least one category for the user to keep notes attached to "categories has many note, notes belong to category" relationship. Marko wrote:> How can I delete category and set all recipes linked to that category to > "no category"? > > The tutorial at O''Reilly says nothing about that...-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Marko, Marko wrote:> Conrad Taylor wrote: >> Hi, you''ll simply have to change > > :-) So do I have to make a new Category with name > ''no category'' and than link all recipes to new category?Yes. Because the belongs_to relationship requires that a recipe must have a category.> What if I have Author of recipe...> > table Authors with fields: > > id > first_name > last_name > city > state > street > zip > phone > > Now how do I set "no author" here?The answer depends on the relationship you want to maintain between the various entities. Do you want to make sure that you every Recipe has an Author? What about having Authors hanging around with no contributions? The table definition above has no foreign keys and so, as it stands, you currently have no way to link it to Recipes. These are basic database design questions/concepts that really have nothing to do with Rails. You might want to Google ''database design'' and spend a little time getting your arms around the basics. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---