how to create a table using ActiveRecord alone

Discussion in 'Ruby' started by Li Chen, Sep 11, 2008.

  1. Li Chen

    Li Chen Guest

    Hi all,

    I know I can create a table by running MySql first. I search some
    tutorials on google but they all talk about creating a table using
    MySql-like database then use ActiveRecord to connect them. I wonder if
    it is possible to create a table with ActiveRecord only.

    Thanks,

    Li
    --
    Posted via http://www.ruby-forum.com/.
    Li Chen, Sep 11, 2008
    #1
    1. Advertising

  2. On Sep 11, 2008, at 5:07 PM, Li Chen wrote:

    > Hi all,
    >
    > I know I can create a table by running MySql first. I search some
    > tutorials on google but they all talk about creating a table using
    > MySql-like database then use ActiveRecord to connect them. I wonder if
    > it is possible to create a table with ActiveRecord only.
    >
    > Thanks,
    >
    > Li
    > --
    > Posted via http://www.ruby-forum.com/.
    >


    You could use migrations. But thats just another way of describing the
    table.

    If you want another approach (defining a model and then letting the
    abstraction
    layer create the required database), you could use datamapper
    instead[1].

    Then, you class will look like this:

    1 class Post
    2 include DataMapper::Resource
    3 property :id, Integer, :serial => true
    4 property :title, String
    5 property :subtitle, String :lazy => [:show]
    6 property :body, Text :lazy => [:show]
    7 property :views, Integer, :lazy => [:show]
    8 property :summary, Text
    9 end

    #and

    Post.auto_migrate!

    will create/migrate your table automatically.

    Regards,
    Florian

    [1]: http://www.datamapper.org
    Florian Gilcher, Sep 11, 2008
    #2
    1. Advertising

  3. Li Chen

    Li Chen Guest

    Florian Gilcher wrote:
    > If you want another approach (defining a model and then letting the
    > abstraction
    > layer create the required database), you could use datamapper
    > instead[1].
    >
    > Then, you class will look like this:


    > [1]: http://www.datamapper.org


    I visit the wetsite: http://www.datamapper.org. It says it is not good
    under window system. I wonder how good it is under Vista.





    --
    Posted via http://www.ruby-forum.com/.
    Li Chen, Sep 11, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Hartnett

    how to create stand-alone page in VS

    Tom Hartnett, Nov 7, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    946
    Keith
    Nov 7, 2003
  2. tomer
    Replies:
    6
    Views:
    455
    Ferenc Hechler
    Nov 26, 2004
  3. CVT
    Replies:
    3
    Views:
    378
  4. Praveen Mohanan
    Replies:
    3
    Views:
    5,074
    Tony Morris
    May 4, 2006
  5. Plotinus
    Replies:
    2
    Views:
    283
    Tad McClellan
    Dec 17, 2004
Loading...

Share This Page