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

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


咨詢
建站咨詢
