Imagine a Model named "Trip".
When creating a new trip it's activeTrip attribute must default to
itself.
(So it becomes self-refencing FK in the database table)
The following code does not seem to work. After creating a new object
the active_trip_id field is blank in the database. Any ideas what I'm
doing wrong?
class Trip
include DataMapper::Resource
property :id, Serial
property :name, String, :default => "A lovely new trip"
# Self-referencing FK trip.activeTrip:
has 1, :activeTrip, :class_name => "Trip", :child_key =>
[:active_trip_id]
belongs_to :trip, :class_name => "Trip", :child_key =>
[:active_trip_id]
# Default activeTrip to itself if none specified:
before :save do
activeTrip ||= self
end
end
BIG thanks for your help!
George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" 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/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---