[Nitro] Trying Og example

Brian Candler B.Candler at pobox.com
Tue Aug 23 16:04:02 EDT 2005


On Mon, Aug 22, 2005 at 09:56:49AM +0300, George Moschovitis wrote:
> po = Post.new
> po.title = ..
> ..
> 
> cat.posts << po
> 
> And I 'll make the code block work in the next version.

Thanks. Here are some more things which don't work from the tutorial:

(1)

    # FIXME
    cat = Category['Programming']

This gives the following exception:

ERROR: DB error Unknown column 'Programming' in 'where clause', [SELECT * FROM ogcategory WHERE oid=Programming]

whereas the tutorial says: "As a convenience, Og allows you to lookup the
category using the special property 'name'"

(2)
    po = Post[1]
    p p.title

    # FIXME
    p po.categories[0].title

gives exception "undefined method `categories' for #<Post:...>"

(3)
    com = Comment.new('Hi there')
    p.add_comment(com)

another 'method missing' exception

(4)

    po = Post[1]
    # FIXME
    po.update_properties "body='Hello world'"

Gives the following exception:

/v/build/nitro/og-0.22.0/lib/og/store/sql.rb:334:in `send': undefined method `body='Hello world'' for #<Post:0x82beef4> (NoMethodError)
        from /v/build/nitro/og-0.22.0/lib/og/store/sql.rb:334:in `update'
        from /v/build/nitro/og-0.22.0/lib/og/store/sql.rb:333:in `each'
        from /v/build/nitro/og-0.22.0/lib/og/store/sql.rb:333:in `update'
        from /v/build/nitro/og-0.22.0/lib/og/entity.rb:30:in `update_properties'
        from run.rb:132

(5) The callback function isn't called:

class Post
  ...

  def og_post_insert(conn)
        puts 'Hey, a new post was just posted!'
  end
end

I found a few other errors in the tutorial which I was able to fix - these
are reflected in the attached patch.

Apart from this, it worked just fine :-(

Regards,

Brian.
-------------- next part --------------
--- tutorial.txt.orig	Mon Aug 15 21:24:34 2005
+++ tutorial.txt	Tue Aug 23 21:01:21 2005
@@ -150,9 +150,9 @@
 for PostgreSQL, MySQL, SQLite3, and Oracle. For this example, we'll use the PostgreSQL adapter,
 so add this code after the class definitions.
 
-db = Og::Database.new(
-    :database => 'test',
-    :adapter  => 'psql',
+db = Og.setup(
+    :store    => 'psql',
+    :name     => 'test',
     :user     => 'postgres',
     :password => 'navelrulez'
 )
@@ -180,7 +180,7 @@
 
 Issue the following SQL to see the result:
 
-SELECT * FROM og_post
+SELECT * FROM ogpost
 
 This is nice, but where does the #save method come from?
 Og uses Ruby's advanced introspection features to automatically
@@ -207,7 +207,7 @@
 cat.name = 'Programming'
 cat.save
 
-If you investigate the generated og_category table, you will
+If you investigate the generated ogcategory table, you will
 see an 'oid' column which serves as the primary key. This
 column is added automatically by Og. You can use the oid
 values to lookup objects:
@@ -221,6 +221,7 @@
 As a convenience, Og allows you to lookup the category
 using the special property 'name':
 
+** FIXME: This is broken **
 cat = Category['Programming']
 
 You can lookup objects by name only if the name property is
@@ -317,9 +318,10 @@
 
 cat = Category.create('Programming')
 
+# ** FIXME ** gives "wrong number of arguments (0 for 1) (ArgumentError)"
 cat.add_post { |p|
      p.title = 'Title'
-     p.body = 'Body
+     p.body = 'Body'
 }
 
 cat.add_post { |p|
@@ -340,6 +342,7 @@
 p.title
  => Title
 
+# ** FIXME ** method_missing exception
 p.categories[0].title
  => 'Programming'
 
@@ -350,6 +353,7 @@
 p.comments.size
  => 1
 
+# ** FIXME ** method_missing exception
 p.add_comment { |c|
     c.title = 'Hi there'
 }
@@ -365,10 +369,10 @@
 
 Og provides full access to all features of the underlying RDBMS. Look at the following:
 
-post = Post.select("title='Title' and body='Body'")
+post = Post.select("where title='Title' and body='Body'")
 post.size
  => 1
-post.hits
+post[0].hits
  => 0
 
 Updating existing objects is easy too:
@@ -384,6 +388,7 @@
 You can also update specific properties, for example:
 
 p = Post[1]
+# ** FIXME ** undefined method error
 p.update_properties "body='Hello world'"
 
 p = Post[1]
@@ -431,12 +436,13 @@
 
 For example, the following code defines a callback for the Post class.
 
+** FIXME ** This doesn't work (the callback isn't called)
 class Post
   ...
 
   def og_post_insert(conn)
         puts 'Hey, a new post was just posted!'
-    end
+  end
 end
 
 When post.save is called, you'll get this alert:


More information about the Nitro-general mailing list