Syntax q on ActiveRecord

In my model, if I have a field, that contains the id to another table, twice
(like, primary associate and a secondary associate) I am specifying this as

class Customer < ActiveRecord::Base
    belongs_to: associate :foreign_key => "associatekey1"
    belongs_to: associate :foreign_key => "associatekey2"
end

This doesn't work -- but my question is how SHOULD the syntax for specifying
this look? Thanks, Ike

this question should go to the rubyonrails mailing list.

···

On Oct 31, 2006, at 11:00 AM, Ike wrote:

In my model, if I have a field, that contains the id to another table, twice
(like, primary associate and a secondary associate) I am specifying this as

Just RTFM.

<http://api.rubyonrails.org/&gt;

(s.v. "belongs_to):

  belongs_to :firm, :foreign_key => "client_of"

Notice the comma? Notice where the colons go?

m.

PS The fact that you could bring yourself to write belongs_to: suggests
that you don't know Ruby. Over the course of a long life in computers I
have found that it is helpful to know the basics of the language in
which one is programming (though, to be quite honest, I've written quite
a bit of Perl without obeying that rule)...

···

Ike <rxv@hotmail.com> wrote:

In my model, if I have a field, that contains the id to another table, twice
(like, primary associate and a secondary associate) I am specifying this as

class Customer < ActiveRecord::Base
    belongs_to: associate :foreign_key => "associatekey1"
    belongs_to: associate :foreign_key => "associatekey2"
end

This doesn't work -- but my question is how SHOULD the syntax for specifying
this look?

--
matt neuburg, phd = matt@tidbits.com, Matt Neuburg’s Home Page
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Ike wrote:

In my model, if I have a field, that contains the id to another table, twice (like, primary associate and a secondary associate) I am specifying this as

class Customer < ActiveRecord::Base
   belongs_to: associate :foreign_key => "associatekey1"
   belongs_to: associate :foreign_key => "associatekey2"
end

This doesn't work -- but my question is how SHOULD the syntax for specifying this look? Thanks, Ike

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

Using the column names primary_associate_id and secondary_associate_id, instead of associatekey1 and associatekey2

class Customer < ActiveRecord::Base
  belongs_to :primary_associate, :class_name => 'Associate', :foreign_key => 'primary_associate_id'
  belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key => 'secondary_associate_id'
end

Rails automatically infers the class_name and foreign_key from the name of your association. You can always just name your association whatever you want and specify those things explicitly, like I do here.

"matt neuburg" <matt@tidbits.com> wrote in message
news:1ho2k6a.1bk8gir14ss1c0N%matt@tidbits.com...

···

Ike <rxv@hotmail.com> wrote:

Just RTFM.

<http://api.rubyonrails.org/&gt;

(s.v. "belongs_to):

belongs_to :firm, :foreign_key => "client_of"

Notice the comma? Notice where the colons go?

m.

PS The fact that you could bring yourself to write belongs_to: suggests
that you don't know Ruby. Over the course of a long life in computers I
have found that it is helpful to know the basics of the language in
which one is programming (though, to be quite honest, I've written quite
a bit of Perl without obeying that rule)...

--
matt neuburg, phd = matt@tidbits.com, Matt Neuburg’s Home Page
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

Jesus H. Christ.....it's a TYPO as I was copying by hand, with from the code
on another machine, without considering that. Thanks for being so
chastising. -Ike

matt neuburg wrote:

Just RTFM.

<http://api.rubyonrails.org/&gt;

(s.v. "belongs_to):

  belongs_to :firm, :foreign_key => "client_of"

Notice the comma? Notice where the colons go?

m.

PS The fact that you could bring yourself to write belongs_to: suggests
that you don't know Ruby. Over the course of a long life in computers I
have found that it is helpful to know the basics of the language in
which one is programming (though, to be quite honest, I've written quite
a bit of Perl without obeying that rule)...

Hah, that post was *so* Tom Christiansen like, 10 years ago, on the Perl mailing list. Brings back memories.

Outside of the silly attitude, I'd just like to point out that the placement of the colons in Ruby is very odd compared to other popular programming languages out there. Using a :colon like a $sigil takes some getting used to, and assuming "colon: value" is much more consistent with JSON/YAML/etc.

Point being, that's an easy mistake to make.

-Nate

"Mike Harris" <GENIE@prodigy.net> wrote in message
news:4547AC2E.9020102@prodigy.net...

Ike wrote:

Using the column names primary_associate_id and secondary_associate_id,
instead of associatekey1 and associatekey2

class Customer < ActiveRecord::Base
belongs_to :primary_associate, :class_name => 'Associate', :foreign_key
=> 'primary_associate_id'
belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key
=> 'secondary_associate_id'
end

Rails automatically infers the class_name and foreign_key from the name of
your association. You can always just name your association whatever you
want and specify those things explicitly, like I do here.

Thanks Mike,

I'm stuck with legacy DB column names here however -- I think maybe I need
to look deeper into the ActiveRecord source. Thanks for your help. -Ike

BZZZZZT. This is the ruby-talk mailing list, not the rails mailing list. Take your chastisement elsewhere.

···

On Oct 31, 2006, at 12:04 PM, Mike Harris wrote:

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

Sorry, I must have misunderstand the question. I apologize. m.

···

Ike <rxv@hotmail.com> wrote:

Jesus H. Christ.....it's a TYPO

--
matt neuburg, phd = matt@tidbits.com, Matt Neuburg’s Home Page
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

BZZZZZT. This is the ruby-talk mailing list, not the rails mailing list. Take your chastisement elsewhere.

Rails-schmails. What happened to, "Matz is nice, so we are nice?"

Regards,

Bill

P.S. ............ YOUR MAMA !!!!!!!!!!!!

···

From: "Ryan Davis" <ryand-ruby@zenspider.com>

On Oct 31, 2006, at 12:04 PM, Mike Harris wrote:

Ryan Davis wrote:

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

BZZZZZT. This is the ruby-talk mailing list, not the rails mailing list. Take your chastisement elsewhere.

This is also a newsgroup and I haven't noticed any news groups for rails. While you might not like people asking questions about one of the programs using Ruby on your precious mailing list not everyone is as close-minded as you seem to be.
I only found out about the mailing list after finding the newsgroup and have found no reason to use the mailing list. I am sure that I am not the only one.

···

On Oct 31, 2006, at 12:04 PM, Mike Harris wrote:

Ryan Davis wrote:

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

BZZZZZT. This is the ruby-talk mailing list, not the rails mailing list. Take your chastisement elsewhere.

Ryan, you weren't the rude one, saying "go to the rails mailing list" was both accurate and polite. The rudeness was the other guy. I stand by what I said, saying RTFM is cursing at a stranger, and the question wasn't overly rudimentary.

···

On Oct 31, 2006, at 12:04 PM, Mike Harris wrote:

Ike wrote:

"Mike Harris" <GENIE@prodigy.net> wrote in message news:4547AC2E.9020102@prodigy.net...

Ike wrote:
   
Using the column names primary_associate_id and secondary_associate_id, instead of associatekey1 and associatekey2

class Customer < ActiveRecord::Base
belongs_to :primary_associate, :class_name => 'Associate', :foreign_key => 'primary_associate_id'
belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key => 'secondary_associate_id'
end

Rails automatically infers the class_name and foreign_key from the name of your association. You can always just name your association whatever you want and specify those things explicitly, like I do here.
   
Thanks Mike,

I'm stuck with legacy DB column names here however -- I think maybe I need to look deeper into the ActiveRecord source. Thanks for your help. -Ike

I just changed the names of the columns in my example cause I felt like it. This is perfectly fine as well

class Customer < ActiveRecord::Base
belongs_to :primary_associate, :class_name => 'Associate', :foreign_key => 'associatekey1'
belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key => 'associatekey2'
end

The :foreign_key option tells it the name of the column you are using.

Have you looked at the manual that was linked earlier in the thread?

http://api.rubyonrails.com/

Here's the specific page for this

http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000532

The documentation isn't great, but for most problems at this level it tells you what you need to know.

Michael W. Ryder wrote:

Ryan Davis wrote:

You probably could have looked it up, and it should go on the rails list. However, people don't need to be rude. RTFM should be banned from this list, plus the rails documentation is scattered and it sorta sucks.

BZZZZZT. This is the ruby-talk mailing list, not the rails mailing list. Take your chastisement elsewhere.

This is also a newsgroup and I haven't noticed any news groups for rails. While you might not like people asking questions about one of the programs using Ruby on your precious mailing list not everyone is as close-minded as you seem to be.
I only found out about the mailing list after finding the newsgroup and have found no reason to use the mailing list. I am sure that I am not the only one.

Wow, this is getting almost as exciting as C++ land.

···

On Oct 31, 2006, at 12:04 PM, Mike Harris wrote: