Created
April 27, 2010 08:54
-
-
Save whalec/380508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateMedia < ActiveRecord::Migration | |
def self.up | |
create_table :media do |t| | |
t.string :name, :null => false | |
t.text :description | |
t.references :asset, :null => false | |
t.timestamps | |
end | |
execute <<-EOS | |
ALTER TABLE media | |
ADD FOREIGN KEY (asset_id) | |
REFERENCES assets (id) | |
ON DELETE CASCADE | |
ON UPDATE CASCADE; | |
EOS | |
end | |
def self.down | |
drop_table :medias | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete ignores AR callbacks | |
it "should cascade delete the asset if deleted" do | |
asset = @media.asset | |
@media.delete | |
asset.reload.should be_nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahh right of course. Cool thanks I've got it now.