<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Apr 8, 2011 at 9:42 PM, Clint Moore <span dir="ltr">&lt;<a href="mailto:clint@ivy.io">clint@ivy.io</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br><br><div class="gmail_quote"><div class="im">On Thu, Apr 7, 2011 at 12:01 PM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div></div><div>First, what&#39;s the &#39;right way&#39; to get a string representation of a Key?</div>



<div>I generate select form elements from subsets of data in a table.  Usually, resulting in &#39;select name=&quot;name_column&quot; value=&quot;id_column&quot;&#39;</div><div><br></div></blockquote></div><div>I would probably use the Show instance, unless you have a compelling reason not to.</div>


</div></div></blockquote><div><br></div></div><div>Show on the key gives me &#39;TableId 1&#39; instead of simply 1.  I&#39;m assuming the expectation is not to split the table name off every time, though I don&#39;t see a function to get just the id of a row.  ie tableId </div>


<div><br></div><div>&gt; x &lt;- myConnect $ selectList [TableNameNe &quot;honk&quot;] [] 0 0</div><div>&gt; fst $ head x</div><div>TableId 1</div><div><br></div><div>&gt; tableId $ snd x  &lt;- convenient!</div><div class="im">

<div><br></div></div></div></blockquote><div><br></div><div>I think the function you&#39;re looking for is fromPersistKey, which will give you back an Int64. Be warned, however, that in Persistent 0.5, it will instead give you back a PersistValue, since some backends (MongoDB in particular) use more than 64 bits for their keys.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im"><div>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>Second, for types that have relationships, is there a shortcut or something I&#39;m not seeing that will allow me to derive Data and Typeable?</div>


<div>example:</div><div><br></div><div>Species</div><div> name String Eq</div><div> deriving Data Typeable</div><div><br></div><div>Animal</div><div> name String</div><div> species SpeciesId</div><div> deriving Data Typeable  &lt;-- error!  There aren&#39;t instances generated, at least that it can find, of SpeciesId for Data.Data</div>




<div><div></div><div>
<div><br></div></div></div></blockquote></div><div>I wanted to enable this by default in Persistent, but it would require user code to have DeriveDataTypeable enabled. I can consider putting it back in, but I wouldn&#39;t mind web-devels input.</div>


</div></div></blockquote><div><br></div></div><div>For my uses, the only place that this makes life much easier is when using HStringTemplate.  If it were enabled, you could simply set a row as an argument directly with &#39;setAttribute&#39; instead of having to massage the data beforehand.</div>


<div><br></div><div>Other than that, I can&#39;t think of a compelling reason to enable it by default.</div><div><br></div><div>As I write this, I thought perhaps you could add cabal flags to enable this if you knew that you needed it, but then you start having to litter your code with #ifdefs and that starts to make code look very ugly very quickly.</div>


<div><br></div><div>Maybe someone has another compelling use case for enabling this by default?</div><div><br></div><div> </div></div>
</blockquote></div><br><div>I definitely don&#39;t want to deal with cabal flags for this, it would mean that some packages wouldn&#39;t install on your system depending on how you build Persistent. For your case, it might be acceptable to just use standalone deriving declarations, ie:</div>

<div><br></div><div>deriving instance Data SpeciesId</div><div>deriving instance Data Animal</div><div>...</div><div><br></div><div>Michael</div></div>