<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mundo Ruby &#187; ActiveRecord</title>
	<atom:link href="http://www.mundoruby.com.ar/tag/activerecord/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mundoruby.com.ar</link>
	<description>Ruby Artists, Hackers y otras yerbas ...</description>
	<lastBuildDate>Wed, 12 Aug 2009 23:02:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Obtener registros previos/siguientes con ActiveRecord</title>
		<link>http://www.mundoruby.com.ar/2009/03/25/obtener-registros-previossiguientes-con-activerecord/</link>
		<comments>http://www.mundoruby.com.ar/2009/03/25/obtener-registros-previossiguientes-con-activerecord/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 14:31:49 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=56</guid>
		<description><![CDATA[Según se vaya avanzando en un proyecto, es posible que nos veamos en la necesidad de encotrar los registros vecinos para el que estemos utilizando en un momento dado. De este modo, por ejemplo si uno esta posicionado en un registro y desea obtener el siguiente, tener algo como &#8220;next&#8221; o &#8220;previous&#8221; sería muy útil.
Acts_as_ordered [...]]]></description>
			<content:encoded><![CDATA[<p>Según se vaya avanzando en un proyecto, es posible que nos veamos en la necesidad de encotrar los registros vecinos para el que estemos utilizando en un momento dado. De este modo, por ejemplo si uno esta posicionado en un registro y desea obtener el siguiente, tener algo como &#8220;next&#8221; o &#8220;previous&#8221; sería muy útil.</p>
<p>Acts_as_ordered es un plugin interesante para obtener los registros previos o siguientes a uno determinado.Es muy versatil y potente. Se puede descargar de <a href="http://svn.viney.net.nz/things/rails/plugins/acts_as_ordered">aquí</a>.</p>
<p>Para mi cuestiones particulares, lo resolví a lo bestia, incluyendo estos dos métodos en la clase que los requería.</p>
<ol>
<li>
<div><span>def</span> <span>self</span>.<span>previous</span> id</div>
</li>
<li>
<div>prev_id= <span>self</span>.<span>minimum</span><span>(</span><span>:id</span>, <span>:conditions</span> <span>=&gt;</span> <span>[</span><span>'id &gt; ?'</span>, id<span>]</span><span>)</span></div>
</li>
<li>
<div><span>self</span>.<span>find</span><span>(</span>prev_id<span>)</span></div>
</li>
<li>
<div><span>end</span></div>
</li>
<li><span><span> </span></span></li>
<li>
<div><span>def</span> <span>self</span>.<span>next</span> id</div>
</li>
<li>
<div>next_id=<span>self</span>.<span>maximum</span><span>(</span><span>:id</span>, <span>:conditions</span> <span>=&gt;</span> <span>[</span><span>'id &lt; ?'</span>, id<span>]</span><span>)</span></div>
</li>
<li>
<div><span>self</span>.<span>find</span><span>(</span>next_id<span>)</span></div>
</li>
<li>
<div><span>end</span></div>
</li>
</ol>
<p>Saludos</p>
<p>Inspirado de un reply en <a href="http://duanesbrain.blogspot.com/2008/11/ruby-on-rails-get-next-activerecord.html">Duane&#8217;s Brain</a></p>
<p><a href="http://www.rodolinux.com.ar/node/123">leer más</a></p>
<p>(Via <a href="http://www.rodolinux.com.ar">Rodolinux &#8211; Rodolinux&#8217;s Playground</a>.) Original Link: <a href="http://www.rodolinux.com.ar/node/123#comments">Obtener registros previos/siguientes con ActiveRecord</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/03/25/obtener-registros-previossiguientes-con-activerecord/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creando consultas ActiveRecord a partir de SQL</title>
		<link>http://www.mundoruby.com.ar/2009/03/22/creando-consultas-activerecord-a-partir-de-sql/</link>
		<comments>http://www.mundoruby.com.ar/2009/03/22/creando-consultas-activerecord-a-partir-de-sql/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 13:47:21 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=52</guid>
		<description><![CDATA[
Buscando la razón por la cual me falla un find_each dentro de un rake, me encontré con este sitio que sin dudas no deja de ser interesante. Suele pasar que tenemos en claro como construir una sentencia SQL pero no sabemos como hacerlo en ActiveRecord. Este pequeño script lo resuelve. Lo estuve probando y hay [...]]]></description>
			<content:encoded><![CDATA[<p>
Buscando la razón por la cual me falla un find_each dentro de un rake, me encontré con este <a href="http://rorbuilder.info/r/sql2arf/index.html">sitio</a> que sin dudas no deja de ser interesante. Suele pasar que tenemos en claro como construir una sentencia SQL pero no sabemos como hacerlo en ActiveRecord. Este pequeño script lo resuelve. Lo estuve probando y hay casos en los que no devuelve nada, como ser pasando rangos con BETWEEN, por ejemplo.</p>
<p><code><br />
 select * from members where first_name = 'Harold' and age = '34'<br />
 => Members.find(:all, :conditions => {:age => "34", :first_name => "Harold"}</p>
<p> select * from members<br />
 => Members.find(:all)</p>
<p> select * from members where first_name = 'Harold'<br />
 => Members.find(:all, :conditions => {:first_name => "Harold"}</p>
<p> select * from members where first_name like '%Harold%'<br />
 => Members.find(:all, :conditions => ["first_name like ?", '%Harold%'])<br />
</code></p>
<p><a href="http://www.rodolinux.com.ar/node/122">leer más</a></p>
<p>(Via <a href="http://www.rodolinux.com.ar">Rodolinux &#8211; Rodolinux&#8217;s Playground</a>.)Original Link: <a href="http://www.rodolinux.com.ar/node/122#comments">Creando consultas ActiveRecord a partir de SQL</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/03/22/creando-consultas-activerecord-a-partir-de-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acts as state machine y metaprogramming</title>
		<link>http://www.mundoruby.com.ar/2009/03/20/acts-as-state-machine-y-metaprogramming/</link>
		<comments>http://www.mundoruby.com.ar/2009/03/20/acts-as-state-machine-y-metaprogramming/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 19:30:33 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=26</guid>
		<description><![CDATA[
Hace bastante que vengo usando la genial biblioteca &#8220;Acts as state machine&#8221; que nos permite tener un máquina de estados finita (o autómata finito) en un modelo Active Record y a partir de las últimas versiones en cualquier objeto Ruby, y desde hace un tiempito que vengo pensando &#8220;Qué bueno sería que ASSM te genere [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'>
<p>Hace bastante que vengo usando la genial biblioteca <strong>&#8220;Acts as state machine&#8221;</strong> que nos permite tener un <strong>máquina de estados finita</strong> (o autómata finito) en un modelo Active Record y a partir de las últimas versiones en cualquier objeto Ruby, y desde hace un tiempito que vengo pensando &#8220;Qué bueno sería que ASSM te genere un named_scope por cada estado posible&#8221;, entonces si por ejemplo tenemos 2 estados: <strong>active</strong>, <strong>inactive</strong> podríamos hacer algo así:</p>
<pre>User.inactive # Esto retorna todos los usuarios con estado inactive
User.active # Esto retorna todos los usuarios con estado active</pre>
<p>Bueno, acá está la solución que se me ocurrió:</p>
<pre>class User   &lt; ActiveRecord::Base
   acts_as_state_machine :initial =&gt; :inactive
   state :inactive
   state :active

   event :active do
     transitions :from =&gt; :inactive, :to =&gt; :active
   end

   def initialize(*args)
      self.class.define_named_scopes
      super *args
    end

  def self.define_named_scopes
    self.states.each{|st|
    self.named_scope st, :conditions =&gt; { :state =&gt; st.to_s },
                      : order =&gt; 'created_at DESC'
    }
  end
end</pre>
<p>Nice eh! tenemos un método que escribe los named_scope por nosotros y seguro que se puede mejorar o quizás agregar una opción a AASM para que lo haga cuando lo deseemos, el tema es que cómo necesitamos la lista de los estados, debemos ejecutar esto después de especificar los mismos, aunque una solución más elegante sería modificar AASM y hacer que los named_scope se genere cada vez que especificamos un estado.</p>
<p>Hasta la próxima!</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gastonramos.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gastonramos.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gastonramos.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gastonramos.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gastonramos.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gastonramos.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gastonramos.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gastonramos.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gastonramos.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gastonramos.wordpress.com/301/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gastonramos.wordpress.com&#038;blog=1034400&#038;post=301&#038;subd=gastonramos&#038;ref=&#038;feed=1" /></div>
<p>(Via <a href="http://gastonramos.wordpress.com">Gastón Ramos &#8211; Ruby, Rails&#8230;</a>.) Original Link: <a href="http://gastonramos.wordpress.com/2009/03/20/acts-as-state-machine-y-metaprogramming/#comments">Acts as state machine y metaprogramming</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/03/20/acts-as-state-machine-y-metaprogramming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usar fb_adaptor con versiones viejas de Interbase</title>
		<link>http://www.mundoruby.com.ar/2009/03/20/usar-fb_adaptor-con-versiones-viejas-de-interbase/</link>
		<comments>http://www.mundoruby.com.ar/2009/03/20/usar-fb_adaptor-con-versiones-viejas-de-interbase/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:56:03 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[DataBase]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=5</guid>
		<description><![CDATA[

Como comenté en el update de post anterior respecto de como usar Firebird con JRuby , me era imposible insertar registros con sentencias sql, por lo que tuve que revisar otras opciones.


Intenté compilar el adaptador fb en JRuby sin éxito por tener dependencias nativas, por lo que decidí intentar con Ruby Enterprise Edition.

leer más

(Via Rodolinux [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>
Como comenté en el update de <a href="http://www.rodolinux.com.ar/node/115">post anterior respecto de como usar Firebird con JRuby</a> , me era imposible insertar registros con sentencias sql, por lo que tuve que revisar otras opciones.
</p>
<p>
Intenté compilar el adaptador <a href="http://github.com/rowland/fb_adapter/tree/master">fb</a> en JRuby sin éxito por tener dependencias nativas, por lo que decidí intentar con <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.
</p>
<p><a href="http://www.rodolinux.com.ar/node/120">leer más</a></p>
</div>
<p>(Via <a href="http://www.rodolinux.com.ar">Rodolinux &#8211; Rodolinux&#8217;s Playground</a>.) Original Link:<a href="http://www.rodolinux.com.ar/node/120">Usar fb_adaptor con versiones viejas de Interbase</a> </p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/03/20/usar-fb_adaptor-con-versiones-viejas-de-interbase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

