<?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>def Tenako.blog () end &#187; rails clave foranea</title>
	<atom:link href="http://blog.tenako.com/tag/rails-clave-foranea/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tenako.com</link>
	<description></description>
	<lastBuildDate>Sun, 10 Jul 2011 10:15:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rails: Claves foraneas en las migraciones</title>
		<link>http://blog.tenako.com/2008/10/08/rails-claves-foraneas-en-las-migraciones/</link>
		<comments>http://blog.tenako.com/2008/10/08/rails-claves-foraneas-en-las-migraciones/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 22:37:47 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails clave foranea]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=13</guid>
		<description><![CDATA[Hay varias formas para indicar la restriccion que implica una clave foranea en nuestras tablas cuando estamos utilizando las migraciones para definir dichas tablas. La primera y mas &#8220;tosca&#8221; consiste en indicar a pelo dicha restriccion: class CreateOrder &#60; ActiveRecord::Migration def self.up t.string :name t.integer :user_id &#160; execute &#34;alter table table add constraint fk_table_user \ [...]]]></description>
			<content:encoded><![CDATA[<p>Hay varias formas para indicar la restriccion que implica una clave foranea en nuestras tablas cuando estamos utilizando las migraciones para definir dichas tablas.</p>
<p>La primera y mas &#8220;tosca&#8221; consiste en indicar a pelo dicha restriccion:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateOrder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:name</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>
&nbsp;
      execute <span style="color:#996600;">&quot;alter table table add constraint fk_table_user <span style="color:#000099;">\ </span>
         foreign key (user_id) references users (id)&quot;</span>
&nbsp;
   <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
   ...
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Pero tambien podemos aprovechar algun plugin para facilitarnos el trabajo.Es aqui donde entra en juego este plugin que descubri hoy.</p>
<ul>
<li><a href="http://www.redhillonrails.org/redhillonrails_core.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.redhillonrails.org');">Redhillonrails_core</a></li>
</ul>
<p>Con este plugin podemos rehacer lo anterior de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateOrder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#ff3333; font-weight:bold;">:name</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:user_id</span>
&nbsp;
      t.<span style="color:#9900CC;">foreign_key</span> <span style="color:#ff3333; font-weight:bold;">:users</span>,:user_id,:id
&nbsp;
   <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
   ...
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Bastante mejor, no?.Este plugin tiene disponible adaptadores para mysql y postgresql.</p>
<p>Aqui teneis los <a href="http://www.redhillonrails.org/index.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.redhillonrails.org');">otros plugins</a> que tienen disponibles. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2008/10/08/rails-claves-foraneas-en-las-migraciones/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

