新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Ruby框架OG與ActiveRecord不同之處
我們通過對(duì)Ruby語言的深入學(xué)習(xí)中知道,有兩種ORM框架可以幫助我們靈活的編寫Ruby語言。下面我們將會(huì)介紹其中一種ORM框架,Ruby框架OG。#t#

當(dāng)我們需要定義一個(gè)存儲(chǔ)的類時(shí),我們能夠使用property方法使用Ruby框架OG:
- classSomeClass
- property:alpha,String
- property:beta,String
- property:gamma,String
- end
Ruby框架OG連接數(shù)據(jù)庫:
- db=Og::Database.new
(:destroy=>false,- :name=>'mydb',
- :store=>:mysql,
- :user=>'hal9000',
- :password=>'chandra')
每一個(gè)對(duì)象都有一個(gè)save方法來插入數(shù)據(jù)庫數(shù)據(jù):
- obj=SomeClass.new
- obj.alpha="Poole"
- obj.beta="Whitehead"
- obj.gamma="Kaminski"
- obj.save
還有一些描述傳統(tǒng)數(shù)據(jù)庫中的對(duì)象關(guān)系的Ruby框架OG使用方法:
- classDog
- has_one:house
- belongs_to:owner
- has_many:fleas
- end
網(wǎng)站名稱:Ruby框架OG與ActiveRecord不同之處
網(wǎng)站地址:http://www.dlmjj.cn/article/djpdcec.html


咨詢
建站咨詢
