+-- | Specify how to convert between the two representations NewsTeam
+-- (database) and NewsTeamXml (XML).
+instance ToFromXml NewsTeam where
+ type Xml NewsTeam = NewsTeamXml
+ type Container NewsTeam = Message
+ -- Use a record wildcard here so GHC doesn't complain that we never
+ -- used our named fields.
+ to_xml (NewsTeam {..}) = NewsTeamXml db_team_name
+ -- We can't create a DefaultKey Message...
+ from_xml = error "Called from_xml on a NewsTeam"
+ -- unless we're handed one.
+ from_xml_fk key = (NewsTeam key) . xml_team_name
+
+
+-- | The database type for locations as they show up in the news. We
+-- need this separate from its XML representation because of the
+-- DefaultKey pointing to a message. We don't know how to create one
+-- of those unless we've just inserted a message into the database,
+-- so it screws up pickling.
+data NewsLocation =
+ NewsLocation {
+ loc_news_id :: DefaultKey Message, -- ^ foreign key.
+ db_city ::String,
+ db_state :: String,
+ db_country :: String }
+deriving instance Eq NewsLocation -- Standalone instances necessary for
+deriving instance Show NewsLocation -- Groundhog types with DefaultKeys
+
+-- | The XML type for locations as they show up in the news. See
+-- 'NewsLocation' for why there are two types.
+data NewsLocationXml =
+ NewsLocationXml {
+ xml_city :: String,
+ xml_state :: String,
+ xml_country :: String }
+ deriving (Eq, Show)
+
+
+-- | Specify how to convert between the two representations
+-- NewsLocation (database) and NewsLocationXml (XML).
+instance ToFromXml NewsLocation where
+ type Xml NewsLocation = NewsLocationXml
+ type Container NewsLocation = Message
+ -- Use a record wildcard here so GHC doesn't complain that we never
+ -- used our named fields.
+ to_xml (NewsLocation {..}) = NewsLocationXml db_city db_state db_country
+ -- We can't create a DefaultKey Message...
+ from_xml = error "Called from_xml on a NewsLocation"
+ -- unless we're given one.
+ from_xml_fk key (NewsLocationXml x y z) = NewsLocation key x y z
+
+
+-- | The msg_id child of <message> contains an event_id attribute; we
+-- embed it into the 'Message' type. We (pointlessly) use the "db_"
+-- prefix here so that the two names collide on "id" when Groundhog
+-- is creating its fields using our field namer.