similar to: belongs_to and lookup tables

Displaying 20 results from an estimated 1000 matches similar to: "belongs_to and lookup tables"

2006 Jun 21
1
Migration with foreign key won''t work
Hi all I use the plugin which supports foreign keys with migrations: http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin/versions/12 I have created the following migration file: class AddArtistsTable < ActiveRecord::Migration def self.up create_table :artists, :force => true do |t| t.column :name, :string, :limit => 100 t.column :artist_type_id,
2006 May 16
2
Validate Before Delete
I have an Order model with a ''status'' column. What I want to be able to do is validate that the status of the Order is not completed before it is allowed to be deleted. I tried the following method in my Model, but it appears that this only works for an :update or :create on the record. Anyone know how to do this, and if it should be in the model or the controller?
2006 Aug 01
3
Validation on ActiveRecord destruction
Rails has many built in validation methods to ensure that an ActiveRecord instance cannot be created or updated under certain situations (typically caused by invalid data). However, I can find no methods to govern whether an ActiveRecord instance can be destroyed. Essentially, I wish an error to be raised when a user tries to delete an ActiveRecord without first adhering to a certain set of
2006 Dec 07
2
validate_on_destroy ?
What''s the best way to validate_on_destroy. Rails only seems to include validate_on_create and validate_on_update methods. I don''t want to resort to doing: before_destroy do |j| raise "There is an error" if j.etc end Is there a way of finding out what action (create/update/destroy) is being performed if I use the ''validate'' method? -- Posted via
2006 Mar 24
2
before_destroy not called
Hello, I''m trying to intercept delete call in my model but before_destroy callback is never called... Somebody knows why ? Thanks The controller : def delete Image.delete(params[:id]) redirect_to :action => "list" end The model : class Image < ActiveRecord::Base set_table_name "publish_images" belongs_to :article before_destroy :on_destroy
2006 Jul 20
5
How can I make has_many prevent a delete that would lead to orphans?
e.g. class Asset < ActiveRecord::Base validates_presence_of :asset_number, :make, :model, :location, :name, :serial_number validates_numericality_of :asset_number validates_uniqueness_of :asset_number belongs_to :user belongs_to :location belongs_to :asset_type, :foreign_key => ''type_id'' end class Location < ActiveRecord::Base validates_presence_of :name
2005 Oct 23
12
Showing a neat error message
Hi All, I''m trying to prevent users from deleting a folder that has contents like this: class Folder < ActiveRecord::Base has_many :myfiles has_many :folders belongs_to :folder validates_uniqueness_of :name, :scope => "folder_id" before_destroy :dont_destroy_folder_with_contents def dont_destroy_folder_with_contents if Folder.find(id) != nil ||
2006 Feb 18
5
don''t destroy last user
How would I stop the last user being deleted. The following code doesn''t work. before_destroy :dont_destroy_last_user # Don''t delete user if it the last one def dont_destroy_last_User raise "Can''t destroy last user" if User.length < 1 end -- Posted via http://www.ruby-forum.com/.
2008 Jul 04
2
How do change catalog before catalog is delted?
In my rails application,there are two models:post and catalog. One post has a catalog,and one catalog has many posts. When I delete a catalog,the posts belongs to the catalog will not be shown normal,for it''s catalog is no existed. Now I want to create(if the ''Defalut catalog'' is not existed) a ''Defalut catalog'' in catalogs table,and make the
2007 Jun 29
1
Speeding up :dependent => :destroy
I have a tree of models that represent a book. Looks like this: book sections documents paragraphs index entries glossary entries footnotes index entries glossary entries These are all models with has_many from parent and the child has belongs_to. They also all have dependent => :destroy
2006 Mar 13
6
:dependent => :destroy
Hi, There is something I don''t understand about :dependent => :destroy. I hope someone can help me. Consider this code: class Folder < ActiveRecord::Base has_many :myfiles has_many :folders has_many :group_folders, :dependent => :destroy validates_uniqueness_of :name, :scope => "folder_id" validates_presence_of :name before_destroy
2006 Apr 13
2
Dynamic finder conditions
Hi everyone, I''ve been working on some code which will take params and turn them into a WHERE clause for the :conditions option in finder methods. So far I''ve been able to do some very simple text matching. I''d like to be able to support ranges, and then go from there (in fact I''ve added code for date ranges but I''m embarrassed of it so I
2006 Mar 14
5
GROUP BY and SUM
I have orders, order_items, and products. I want to collate several orders so that I can get a SUM of quantities ordered for each product etc. Can I say something like (the below gives an error on :sum, and ignores :group) OrderItem.find(:all, :sum => ''quantity'', :group => ''product_id'', :include => [:order, :product]) I want to get back a
2006 Jun 23
10
Don''t un-admin the last administrator
I have a User class with a field called admin which is a boolean that determines if the user is or is not an administrator. I want to make it impossible for the last administrator for an account to be removed from the system. I need to protect against this both when deleting a user and when editing a user as you can revoke a user''s administrator privileges via a form. User
2008 Mar 17
4
RSpec''ing model association callbacks
Hi all, i''m learning rspec and i must admit i really love it. But at the time i started learning it, i already developed my models classes and their callbacks. Now i''m trying to get a 100% coverage of my code but i cannot reach it because i do not understand how to spec my callbacks. Look at this for example: ----------------- User Model class User < ActiveRecord::Base
2003 Feb 09
1
label storage and conversions: DBMS and R
Hi R users, I am new to using DBMS with R for large datasets. Thanks to all who responded with useful suggestion to my earlier postings about using large datasets and DBMS with R. I am writing to get some help about how to design good tables in DBMS to take full advantage of the wonderful built-in facilities in R, like labels. I am using RMySQL client. Because R makes good use of variable
2006 Feb 25
7
Help with DRY: too much code in my view
I''m a newbie to rails, and really to the whole DRY and MVC thing as well, except where I accidentally fell into things doing it my own way in the past. I''ve got a fairly complex DB structure I want to create an interface for using Rails. Getting simple tables to display, edit, save, not too much problem there. But where I''m having trouble is figuring out where to
2005 Nov 26
3
Several questions about Ferret.
Hi. First of all I would like to say "thank you" to David for its really valuable work. Ferret is a great project and it have great future. Well now is my questions as beginner in Ferret. How to remove ALL documents from index. Remove files is not a solution. I am interesting in something like index.remove_index or something like this. What is a usual way of doing it?? What is the
2009 Apr 02
3
error_messages_for does not display the error
Hi all I''ve approached Rails since a couple of months to develop a quick application for my company. Fantastic framework. As every noob, I do have some gaps to cover. The one which is giving me a little frustration, generated by my lack of knowledge is as follows. I need to make sure the region object is not deleted if there are countries associated with it. I solved this by putting a
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM relationship to the other. For example: CREATE TABLE people (id INT, name TEXT); CREATE TABLE teams (id INT, name TEXT); CREATE TABLE people_teams (person_id INT, team_id INT); The person model has: has_and_belongs_to_many :teams And the team model has: has_and_belongs_to_many :people The trouble comes when trying to destroy