Someone asked me on my blog about doing trees in Sequel. I tried the
following:

<<
DB = Sequel.sqlite # Create an in-memory database

# Create a new Post table with columns of
# id, name, and popupost2tion.
DB.create_table :posts do
    primary_key :id
    column :post, :text, :unique=>true
end

# Create a comments table that links to the
# post with a foreign_key
DB.create_table :comments do
    primary_key :id
    column :ct, :text
    column :name, :text
    foreign_key :post_id, :posts
    foreign_key :comment_id, :comments
end

# Create a Post model stating that we'll have comments for each post.
class Post < Sequel::Model;
    one_to_many :comments
end

# Create a Comment model stating that a comment will belong to one post.
class Comment < Sequel::Model
    many_to_one :post
    many_to_one :comment
    one_to_many :comments
end

>>

and everything seems to work fine. I have posts which have comments. Each
comment belongs to a post but can also have a parent post.

Is this the best way to do things? Is there anything I'm missing?

-- 
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to