<?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"
	>
<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>
	<pubDate>Thu, 28 Aug 2008 20:05:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Dr Nic</title>
		<link>http://drnicwilliams.com/2006/08/01/what-is-a-composite-key-in-rails/#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-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 "should" 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't use CPKs.</description>
		<content:encoded><![CDATA[<p>BTW - 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 - as we know - 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-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'm embarassed to say that I found and installed 0.6.2 even before I saw your reply! I came back here to say "never mind", 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-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-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'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's shameful that Rails didn't have it already.

Now, I believe that I've found either a bug, or a place where I'm doing something drastically wrong... I suspect the former.

I'm using mysql Ver 14.12. I'm using version 0.3.3 of your composite_primary_keys library. Everything seems to work well with it so far, but I'm running into this.

I have a table "changelists"; in changelist.rb, I call:
	set_primary_keys :cl_num, :port_id
	has_many :cl_files, :foreign_key =&#62; [:cl_num, :port_id]

(As an aside: I find that whenever I try to use ":foreign_keys" instead of ":foreign_key", 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 =&#62; [:cl_num, :port_id]

So far this seems to work fine. Maybe I'm doing something wrong that's obvious to you and not me. (Both the "changelists" and the "cl_files" tables have both the "cl_num" and "port_id" 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't think I've ever seen this type of structuring of an SQL query before, at least not in MySQL. (I'm referring to the contents of the "where" clause.) My guess is that this is valid syntax on some other database solution, but not in MySQL. (Or else I'm doing something wrong. :)

My workaround is this: in changelists_controller.rb, in the "def show" 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'll be following your progress. If there'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 - 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-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't state explicitly:

@membership = Membership.find(12,1)
@membership.id
=&gt; [12,1]
@membership.id.class
=&gt; CompositeIds
@membership.id.to_s
=&gt; "12,1"
@membership.to_param
=&gt; "12,1"</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>
