<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: What is a composite key in Rails?</title>
	<atom:link href="http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Mon, 30 Apr 2012 17:04:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-14</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Mon, 07 Aug 2006 21:43:47 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-14</guid>
		<description>Great! :)</description>
		<content:encoded><![CDATA[<p>Great! <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-13</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Mon, 07 Aug 2006 21:42:48 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-13</guid>
		<description>BTW - I agree that Rails &quot;should&quot; have composite key support, but no one til now has had the desire to write the code. I think it will be better to keep the code outside of Rails until its perfect else changes will get stuck with the core team who - as we know - don&#039;t use CPKs.</description>
		<content:encoded><![CDATA[<p>BTW &#8211; I agree that Rails &#8220;should&#8221; have composite key support, but no one til now has had the desire to write the code. I think it will be better to keep the code outside of Rails until its perfect else changes will get stuck with the core team who &#8211; as we know &#8211; don&#8217;t use CPKs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IQpierce</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-12</link>
		<dc:creator>IQpierce</dc:creator>
		<pubDate>Mon, 07 Aug 2006 21:42:15 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-12</guid>
		<description>Wow, not only did you reply with lightning speed, but I&#039;m embarassed to say that I found and installed 0.6.2 even before I saw your reply! I came back here to say &quot;never mind&quot;, and you already had the right answer. :)

My show.rhtml page works fine now! Thanks Dr. Nic! :)</description>
		<content:encoded><![CDATA[<p>Wow, not only did you reply with lightning speed, but I&#8217;m embarassed to say that I found and installed 0.6.2 even before I saw your reply! I came back here to say &#8220;never mind&#8221;, and you already had the right answer. <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>My show.rhtml page works fine now! Thanks Dr. Nic! <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-11</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Mon, 07 Aug 2006 21:40:06 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-11</guid>
		<description>Composite foreign keys have been recently added in v0.6.2

Get these by:

gem install composite_primary_keys

Let me know if you have any problems with the new release.</description>
		<content:encoded><![CDATA[<p>Composite foreign keys have been recently added in v0.6.2</p>
<p>Get these by:</p>
<p>gem install composite_primary_keys</p>
<p>Let me know if you have any problems with the new release.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IQpierce</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-10</link>
		<dc:creator>IQpierce</dc:creator>
		<pubDate>Mon, 07 Aug 2006 21:37:09 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-10</guid>
		<description>Hi Dr. Nic!!!

First, thank you SO MUCH for developing this. I&#039;m experienced with DB design and inexperienced in both Ruby and Rails, and I was amazed that Rails developers actually believe that composite primary keys are unnecessary, or even undesirable. Thank you so much for supporting this essential feature - it&#039;s shameful that Rails didn&#039;t have it already.

Now, I believe that I&#039;ve found either a bug, or a place where I&#039;m doing something drastically wrong... I suspect the former.

I&#039;m using mysql Ver 14.12. I&#039;m using version 0.3.3 of your composite_primary_keys library. Everything seems to work well with it so far, but I&#039;m running into this.

I have a table &quot;changelists&quot;; in changelist.rb, I call:
	set_primary_keys :cl_num, :port_id
	has_many :cl_files, :foreign_key =&gt; [:cl_num, :port_id]

(As an aside: I find that whenever I try to use &quot;:foreign_keys&quot; instead of &quot;:foreign_key&quot;, I get an error. Is this a bug or my mistake?)

Then I have the table cl_files, with cl_file.rb:
	set_primary_keys :cl_num, :port_id, :real_path
	belongs_to :changelist, :foreign_key =&gt; [:cl_num, :port_id]

So far this seems to work fine. Maybe I&#039;m doing something wrong that&#039;s obvious to you and not me. (Both the &quot;changelists&quot; and the &quot;cl_files&quot; tables have both the &quot;cl_num&quot; and &quot;port_id&quot; columns.)

However, when I go into views\changelists\show.rhtml (for a changelist with port_id of 1 and cl_num of 29692) and try to do the following...



...then I get the following error...

Mysql::Error: Operand should contain 1 column(s): SELECT * FROM cl_files WHERE (cl_files.cl_num,port_id = 29692,1) 

I don&#039;t think I&#039;ve ever seen this type of structuring of an SQL query before, at least not in MySQL. (I&#039;m referring to the contents of the &quot;where&quot; clause.) My guess is that this is valid syntax on some other database solution, but not in MySQL. (Or else I&#039;m doing something wrong. :)

My workaround is this: in changelists_controller.rb, in the &quot;def show&quot; portion, I initialize the array of @cl_files myself:

@cl_files = ClFile.find_all_by_port_id_and_cl_num(params[:port_id],params[:cl_num])

And then I use @cl_files instead of @changelist.cl_files. This apparently results in a call with no problems, and I get the correct array. Still, it would be nice to be able to access that array simply as @changelist.cl_files!

Thanks again for developing this, I&#039;ll be following your progress. If there&#039;s a better place for me to report bugs than here, let me know. :)</description>
		<content:encoded><![CDATA[<p>Hi Dr. Nic!!!</p>
<p>First, thank you SO MUCH for developing this. I&#8217;m experienced with DB design and inexperienced in both Ruby and Rails, and I was amazed that Rails developers actually believe that composite primary keys are unnecessary, or even undesirable. Thank you so much for supporting this essential feature &#8211; it&#8217;s shameful that Rails didn&#8217;t have it already.</p>
<p>Now, I believe that I&#8217;ve found either a bug, or a place where I&#8217;m doing something drastically wrong&#8230; I suspect the former.</p>
<p>I&#8217;m using mysql Ver 14.12. I&#8217;m using version 0.3.3 of your composite_primary_keys library. Everything seems to work well with it so far, but I&#8217;m running into this.</p>
<p>I have a table &#8220;changelists&#8221;; in changelist.rb, I call:<br />
	set_primary_keys :cl_num, :port_id<br />
	has_many :cl_files, :foreign_key =&gt; [:cl_num, :port_id]</p>
<p>(As an aside: I find that whenever I try to use &#8220;:foreign_keys&#8221; instead of &#8220;:foreign_key&#8221;, I get an error. Is this a bug or my mistake?)</p>
<p>Then I have the table cl_files, with cl_file.rb:<br />
	set_primary_keys :cl_num, :port_id, :real_path<br />
	belongs_to :changelist, :foreign_key =&gt; [:cl_num, :port_id]</p>
<p>So far this seems to work fine. Maybe I&#8217;m doing something wrong that&#8217;s obvious to you and not me. (Both the &#8220;changelists&#8221; and the &#8220;cl_files&#8221; tables have both the &#8220;cl_num&#8221; and &#8220;port_id&#8221; columns.)</p>
<p>However, when I go into views\changelists\show.rhtml (for a changelist with port_id of 1 and cl_num of 29692) and try to do the following&#8230;</p>
<p>&#8230;then I get the following error&#8230;</p>
<p>Mysql::Error: Operand should contain 1 column(s): SELECT * FROM cl_files WHERE (cl_files.cl_num,port_id = 29692,1) </p>
<p>I don&#8217;t think I&#8217;ve ever seen this type of structuring of an SQL query before, at least not in MySQL. (I&#8217;m referring to the contents of the &#8220;where&#8221; clause.) My guess is that this is valid syntax on some other database solution, but not in MySQL. (Or else I&#8217;m doing something wrong. <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>My workaround is this: in changelists_controller.rb, in the &#8220;def show&#8221; portion, I initialize the array of @cl_files myself:</p>
<p>@cl_files = ClFile.find_all_by_port_id_and_cl_num(params[:port_id],params[:cl_num])</p>
<p>And then I use @cl_files instead of @changelist.cl_files. This apparently results in a call with no problems, and I get the correct array. Still, it would be nice to be able to access that array simply as @changelist.cl_files!</p>
<p>Thanks again for developing this, I&#8217;ll be following your progress. If there&#8217;s a better place for me to report bugs than here, let me know. <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/comment-page-1/#comment-3</link>
		<dc:creator>Dr Nic</dc:creator>
		<pubDate>Tue, 01 Aug 2006 11:37:08 +0000</pubDate>
		<guid isPermaLink="false">http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#comment-3</guid>
		<description>One thing I didn&#039;t state explicitly:

@membership = Membership.find(12,1)
@membership.id
=&gt; [12,1]
@membership.id.class
=&gt; CompositeIds
@membership.id.to_s
=&gt; &quot;12,1&quot;
@membership.to_param
=&gt; &quot;12,1&quot;</description>
		<content:encoded><![CDATA[<p>One thing I didn&#8217;t state explicitly:</p>
<p>@membership = Membership.find(12,1)<br />
@membership.id<br />
=> [12,1]<br />
@membership.id.class<br />
=> CompositeIds<br />
@membership.id.to_s<br />
=> &#8220;12,1&#8243;<br />
@membership.to_param<br />
=> &#8220;12,1&#8243;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

