[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Syntax q on ActiveRecord

Ike

10/31/2006 7:00:00 PM

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


13 Answers

Ryan Davis

10/31/2006 7:04:00 PM

0


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

this question should go to the rubyonrails mailing list.

matt

10/31/2006 7:11:00 PM

0

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?

Just RTFM.

<http://api.rubyonrail...

(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, http://www.tidbits...
Tiger - http://www.takecontrolbooks.com/tiger-custom...
AppleScript - http://www.amazon.com/gp/product/...
Read TidBITS! It's free and smart. http://www.t...

Ike

10/31/2006 7:24:00 PM

0


"matt neuburg" <matt@tidbits.com> wrote in message
news:1ho2k6a.1bk8gir14ss1c0N%matt@tidbits.com...
> Ike <rxv@hotmail.com> wrote:
>
> Just RTFM.
>
> <http://api.rubyonrail...
>
> (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, http://www.tidbits...
> Tiger - http://www.takecontrolbooks.com/tiger-custom...
> AppleScript - http://www.amazon.com/gp/product/...
> Read TidBITS! It's free and smart. http://www.t...

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


Nate Wiger

10/31/2006 7:58:00 PM

0

matt neuburg wrote:
> Just RTFM.
>
> <http://api.rubyonrail...
>
> (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

10/31/2006 8:04:00 PM

0

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.

Ike

10/31/2006 8:19:00 PM

0


"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


Ryan Davis

10/31/2006 8:41:00 PM

0


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.

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

matt

10/31/2006 8:54:00 PM

0

Ike <rxv@hotmail.com> wrote:

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

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

--
matt neuburg, phd = matt@tidbits.com, http://www.tidbits...
Tiger - http://www.takecontrolbooks.com/tiger-custom...
AppleScript - http://www.amazon.com/gp/product/...
Read TidBITS! It's free and smart. http://www.t...

Bill Kelly

10/31/2006 9:04:00 PM

0

From: "Ryan Davis" <ryand-ruby@zenspider.com>
>
> 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.
>
> 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 !!!!!!!!!!!!



Michael W. Ryder

10/31/2006 9:07:00 PM

0

Ryan Davis wrote:
>
> 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.
>
> 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.