Taulujen lisäys migratella

3 views
Skip to first unread message

torso

unread,
Jun 26, 2008, 4:53:59 AM6/26/08
to Ruby on Rails: Finnish
Moi

Ajattelin kysäistä apua tälläiseen ongelmaan. Minulla on taulut
categories ja notes, tämän jälkeen pitäisi luoda taulu items

CREATE TABLE items (
id smallint(5) unsigned NOT NULL auto_increment,
done tinyint(1) unsigned NOT NULL default '0',
priority tinyint(1) unsigned NOT NULL default '3',
description varchar(40) NOT NULL default '',
due_date date default NULL,
category_id smallint(5) unsigned NOT NULL default '0',
note_id smallint(5) unsigned default NULL,
private tinyint(3) unsigned NOT NULL default '0',
created_on timestamp(14) NOT NULL,
updated_on timestamp(14) NOT NULL,
PRIMARY KEY (id)
) ';

Tein script/generate scaffold item note_id:smallint
category_id:smallint

jonka jälkeen editoin CreateItemsiä

class CreateItems < ActiveRecord::Migration
def self.up
create_table :items do |t|
t.integer :category_id
t.integer :note_id
t.tinyint :done
t.tinyint :priority
t.text :description
t.date :due_date
t.smallint :note_id
t.tinyint :private
t.timestamps
end
end

def self.down
drop_table :items
end
end

Kuinka saan määriteltyä Not Null ja Defaultin tässä yllä olevassa
luokassa.

Edvard Majakari

unread,
Jun 26, 2008, 5:09:02 AM6/26/08
to finnis...@googlegroups.com
> Kuinka saan määriteltyä Not Null ja Defaultin tässä yllä olevassa
> luokassa.

Esim.

t.string :site, :null => false, :default => 'icanhascheezburger.com'

--
"One day, when he was naughty, Mr Bunnsy looked over the hedge into
Farmer Fred's field and it was full of fresh green lettuces. Mr
Bunnsy, however, was not full of lettuces. This did not seem fair."
-- Terry Pratchett, Mr. Bunnsy Has An Adventure

Jarkko Laine

unread,
Jun 26, 2008, 5:58:27 AM6/26/08
to finnis...@googlegroups.com

On 26.6.2008, at 12.09, Edvard Majakari wrote:

>> Kuinka saan määriteltyä Not Null ja Defaultin tässä yllä olevassa
>> luokassa.
>
> Esim.
>
> t.string :site, :null => false, :default => 'icanhascheezburger.com'

Nämä kaikki löytyvät muuten Railsin api-dokumentaatiosta (esim. http://edgedocs.planetargon.org
):

http://edgedocs.planetargon.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M002211
http://edgedocs.planetargon.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#M002278

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi

torso

unread,
Jun 26, 2008, 7:08:40 AM6/26/08
to Ruby on Rails: Finnish
Kiitos vastuksista


On Jun 26, 12:58 pm, Jarkko Laine <jar...@jlaine.net> wrote:
> On 26.6.2008, at 12.09, Edvard Majakari wrote:
>
> >> Kuinka saan määriteltyä Not Null ja Defaultin tässä yllä olevassa
> >> luokassa.
>
> > Esim.
>
> > t.string :site, :null => false, :default => 'icanhascheezburger.com'
>
> Nämä kaikki löytyvät muuten Railsin api-dokumentaatiosta (esim.http://edgedocs.planetargon.org
> ):
>
> http://edgedocs.planetargon.org/classes/ActiveRecord/ConnectionAdapte...http://edgedocs.planetargon.org/classes/ActiveRecord/ConnectionAdapte...
>
> //jarkko
>
> --
> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce.comhttp://odesign.fi
>
> smime.p7s
> 3KDownload
Reply all
Reply to author
Forward
0 new messages