matthewford (owner)

Fork Of

gist: 18334 by fairchild sequel versioning

Revisions

  • f8c480 deimos1986 Tue Oct 21 10:45:09 -0700 2008
  • a91e5d deimos1986 Tue Oct 21 10:20:16 -0700 2008
  • 7d04aa deimos1986 Tue Oct 21 09:22:22 -0700 2008
  • ac1019 fairchild Tue Oct 21 09:06:08 -0700 2008
  • 69ac24 fairchild Tue Oct 21 08:55:52 -0700 2008
gist: 18338 Download_button fork
public
Public Clone URL: git://gist.github.com/18338.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#how i'd imagine this working, and how to just deal with the ticket obj, although just tested and this doesn't quite work. will see if i can fix it tomorrow
 
class Ticket < Sequel::Model
  set_schema do
    foreign_key :ticket_detail_id, :table => :ticket_detail
    # integer :ticket_detail_version
  end
  is(:versioned_fact, {:dimensions => [TicketDetail]})
  one_to_many :ticket_details
 
  def name
    self.current_detail.name
  end
  def name=(n)
   self.current_detail.name = n
  end
  # this could added to the plugin actually
  before_save do
   self.current_detail.save
  end
end
 
class TicketDetail < Sequel::Model
 set_schema do
   foreign_key :ticket_id, :table => :tickets
   #varchar :name
 end
 is :versioned_object
 many_to_one :ticket
end
 
tic = Ticket.create
tic.name = "version 0"
tic.save
 
tic.version!
 
tic.name = "version 1"
tic.save
 
puts tic.name.should == "version 1"
tic.fetch_version = 0
puts tic.name.should == "version 0"