I have a tree… Thanks a lot, Jeremy.

Artem

On Apr 17, 8:00 pm, Jeremy Evans <[email protected]> wrote:
> On Apr 17, 4:23 am, Kane <[email protected]> wrote:
>
>
>
> > class CreateComments < Sequel::Migration
> >   def up
> >     create_table :comments do
> >       primary_key :id
> >       DateTime :created_at, :null => false
> >       Varchar :author, :size => 128, :null => false
> >       Text :data, :null => false
> >       foreign_key :post_id
> >     end
> >   end
> >   def down
> >     drop_table :comments
> >   end
> > end
>
> > #i think something wrong here, but don't know right way to do this
> > class CreateCommentsComments < Sequel::Migration
> >   def up
> >     create_table :comments_comments do
> >       primary_key :id
> >       foreign_key :comment_id, :comments
> >       foreign_key :parent_id, :comments
> >     end
> >   end
> >   def down
> >     drop_table :comments_comments
> >   end
> > end
>
> > class Post < Sequel::Model
> >   one_to_many :comments
> > end
> > class Comment < Sequel::Model
> >   many_to_one :post
> >   many_to_many :comments
> > end
>
> Are you trying to make a tree structure or a graph in the database?
> Meaning, can each comment be associated with multiple parent
> comments?  If yes, you have a graph, if not, you have a tree. you have
> a tree, the following is better:
>
> class CreateComments < Sequel::Migration
>   def up
>     create_table :comments do
>       primary_key :id
>       DateTime :created_at, :null => false
>       varchar :author, :size => 128, :null => false
>       text :data, :null => false
>       foreign_key :post_id, :posts
>       foreign_key :parent_id, :comments
>     end
>   end
>   def down
>     drop_table :comments
>   end
> end
>
> class Comment < Sequel::Model
>   many_to_one :post
>   many_to_one :parent, :class=>Comment
>   one_to_many :children, :class=>Comment, :key=>:parent_id
> end
>
> If you have a graph, you might want the following:
>
> class CreateCommentsComments < Sequel::Migration
>   def up
>     create_table :comments_comments do
>       primary_key :id
>       foreign_key :left_id, :comments
>       foreign_key :right_id, :comments
>     end
>   end
>   def down
>     drop_table :comments_comments
>   end
> end
>
> class Comment < Sequel::Model
>   many_to_one :post
>   many_to_many :comments, :left_key=>:left_id, :right_key=>:right_id
> end
>
> My guess is you want a tree, since you probably don't want to comment
> on multiple comments at once.
>
> Jeremy
--~--~---------~--~----~------------~-------~--~----~
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