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...
on 2007-05-23 14:12
on 2007-05-23 14:23
Hi, you'll simply have to change
on 2007-05-23 14:40
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?
on 2007-05-23 15:59
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...
on 2007-05-23 16:00
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... > 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
on 2007-05-23 16:13
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.