Hi,
Since "belongs_to" does not actually reflect (as an English wording)
the
real association that one object might have to another, I was thinking
about aliasing it using the following code:
class ActiveRecord::Base
class << self
alias :refers_to :belongs_to
alias :is_of :belongs_to
alias :has_a :belongs_to
end
end
Is it a proper way to do that? Or Is there another better alternative?
Panayotis Matsinopoulos
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/Ik9mlWZ7jGEJ.
For more options, visit https://groups.google.com/groups/opt_out.
On Friday, September 14, 2012 8:24:53 AM UTC+1, Panayotis Matsinopoulos wrote:> > Hi, > > Since "belongs_to" does not actually reflect (as an English wording) the > real association that one object might have to another, I was thinking > about aliasing it using the following code: > > class ActiveRecord::Base > class << self > alias :refers_to :belongs_to > alias :is_of :belongs_to > alias :has_a :belongs_to > end > end > > Well I think that would work, but personally I wouldn''t - I think you''resacrificing readability of the source (people have to know/remember about your extensions) just to make it sound better in english (has_a in particular muddies the water further between has_one & belongs_to). Dave Thomas articulated this better than I could a while ago: http://pragdave.blogs.pragprog.com/pragdave/2008/03/the-language-in.html Fred> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/PiHuxshy4Y0J. For more options, visit https://groups.google.com/groups/opt_out.
You may be right, but I have found a lot of other posts on Internet that
they complain about "belongs_to". It does not bear the correct meaning
for
all cases. For example:
class Product
belongs_to :status
end
.....Awful. No, the Product does not "belong" to a Status. It
"has_a"
status.
Also, "belongs" usually means that a "composition"
relationship, such that
if Status were to be removed, the corresponding Product would have to be
removed too.
Another example:
class Product
belongs_to :type
end
....Awful again. The product Types preexist the Products and a Product does
not belong to a type. "is of" a type.
Certainly, the "belongs_to" as a DSL does not describe the domain on
the
particular cases.
Thanks for letting me know that my workaround will work. I will have the
second thoughts on whether to use or not. I have read the article by Dave.
Thanks for that reference too.
On Fri, Sep 14, 2012 at 12:59 PM, Frederick Cheung <
frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
> On Friday, September 14, 2012 8:24:53 AM UTC+1, Panayotis Matsinopoulos
> wrote:
>>
>> Hi,
>>
>> Since "belongs_to" does not actually reflect (as an English
wording) the
>> real association that one object might have to another, I was thinking
>> about aliasing it using the following code:
>>
>> class ActiveRecord::Base
>> class << self
>> alias :refers_to :belongs_to
>> alias :is_of :belongs_to
>> alias :has_a :belongs_to
>> end
>> end
>>
>> Well I think that would work, but personally I wouldn''t - I
think you''re
> sacrificing readability of the source (people have to know/remember about
> your extensions) just to make it sound better in english (has_a in
> particular muddies the water further between has_one & belongs_to).
Dave
> Thomas articulated this better than I could a while ago:
> http://pragdave.blogs.pragprog.com/pragdave/2008/03/the-language-in.html
>
>
> Fred
>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/PiHuxshy4Y0J.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
Panayotis Matsinopoulos
*P.S.:* I am sending SMS over the WEB using Rayo SMS <http://sms.rayo.gr/>
*E-mail*: panayotis-2qElkpaxrV4pvVtuE3Kueg@public.gmane.org
*Site:* http://www.matsinopoulos.gr
*Mobile:* +30 697 26 69 766
*Skype Id: *panayotis.matsinopoulos
*Facebook: *http://www.facebook.com/PanayotisMatsinopoulos
*Twitter:* http://www.twitter.com/pmatsino
*LinkedIN:* http://www.linkedin.com/in/panayotismatsinopoulos
*Github*: https://github.com/pmatsinopoulos
*Rubygems:* https://rubygems.org/profiles/55099
*CodeProject:* http://www.codeproject.com/Members/PanayotisMatsinopoulos
*ODesk Profile:* https://www.odesk.com/users/~~c84135e75d1f2303
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Panayotis Matsinopoulos wrote in post #1076115:> You may be right, but I have found a lot of other posts on Internet that > they complain about "belongs_to". It does not bear the correct meaning > for > all cases. For example: > > class Product > > belongs_to :status > > end > > .....Awful. No, the Product does not "belong" to a Status. It "has_a" > status.The "belongs to" is not really intended to mean what you seem to think it means. The way I think about it is that the product "object" belongs to the status "object". I agree with Frederick. I see no reason to muddy the waters and potentially confuse experience Rails developers. Consistency in naming is far more important than grammar syntax in an API. Besides that, has_many, belongs_to, etc. are internal implementation details. Not need to worry to much about the public API that the are used internally to create: product.status It makes little difference what the internal implementation of Product looks like from the outside. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.