how to create a table using ActiveRecord alone

L

Li Chen

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
 
F

Florian Gilcher

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top