Ok so I am making a forum as my learning project into nitro, now I have only been using ruby for a few weeks now and I find it simple and easy coming from c++. I Have the following dbmodel:
class User property :login, String property :password, String property :first_name, String property :last_name, String property :email, String property :date_created, Date property :user_id, Integer end class Forum property :forum_posts, Integer property :amount_of_forum_posts, Integer property :name_of_forum, String end class Reply property :date_replied, Time property :reply_message, String property :reply_owner, String property :replied_too, String end class Post property :post_created_by, String property :post_created_date, Time property :post_title, String property :post_message, String end
(1 attempts)
Kashia answered:
[UPDATE 2006-11-15]
Set to answered due to unresponsiveness of the questioner.
Og.setup(:store => 'sqlite', :name => 'database_name')
This will add a new Post item.
a = Post.new a.title = 'test title' # ... a.save
This will pull a Post with a known 'oid', which is just a field in the post table and is the standard primary key.
a = Post[5]
a = Post.find(:condition => "title = 'test title'") a = Post.find(:where => "title = 'test title'") a = Post.find(:sql => "select * from ogpost where title = 'test title'") # etc....
There are many more styles to search in the database, look out for EZ, if you are the non SQL type, otherwise the :sql is the most flexible.
This is probably how I would write this, using is Timestamped and relations (like has_many) simplifies the matters quite a bit.
require 'glue/timestamped' class User is Timestamped property :login, String property :password, String property :first_name, String property :last_name, String property :email, String has_many :posts, Post end class Forum is Timestamped property :name, String has_many :posts, Post end class Reply is Timestamped property :message, String belongs_to :owner, User has_one :replied_to, Post def date_replied return @create_time end end class Post is Timestamped belongs_to :owner, User property :title, String property :message, String has_many :replies, Reply end
Usage below.
As always, do the Og.setup after declaring (or requireing) the Models. All you have to do, to change the DB, is to change the :store field of the hash.
Og.setup( :store => 'psql' # etc.. )
Other than that, Og tries to avoid to use special SQL syntax, so it will work on all the databases you named (well, not Oracle yet, but will at a later point as this is already planned). What you have to take care of, is what you write in Post.find(:sql =>....) since Og does not monitor what you write as plain SQL. Just use standard SQL92 and you should basically be fine.
Put .xhtmls in your Template folder, and yes, they will be reloaded when you change them while the server runs (if run in debug mode, live mode will not do this, so you have to restart the service then).
Yes, you should use them, as they make coding simpler, faster and less error prone. An example usage is stated below. The gain is, that one doesn't have to care on how those relations actually work, you just define that a forum has a few messages, which is the only thing you want to know.
f = Forum.new f.name = 'test' f.save u = User.create u.login = 'testuser' # ... u.save p = Post.create p.owner = u p.message = "blabla \n blabla" p.save f.posts << p f.save r = Reply.create r.owner = u r.save p.replies << r #p.add_reply(r) p.save # example to query all messages in a Forum, # ordered by date: messages = Forum.posts(:order_by => 'date')
See http://rubygarden.org/index.cgi/Libraries/og_tutorial.rdoc for an old but good tutorial.