Ruby on Rails Saturday, September 27, 2014

Paolo, 

I think you've going in the right direction but i'd recommend a few changes based on my experience. Translation Agency has different rates for each language. and the rate per language for A -> B Is not the same as B -> A. So its better to maintain the cost details in Another model unique for one direction. 

Language: 
has_many :language_translations


LanguageTranslation
belongs_to :language
belongs_to :target_language, :class_name => "Language"

#An float/integer field for cost. 

Also i dont think you have to specify foreign_key condition unless your association name and foreignkeys are different.. 

eg blongs_to :car,  :class_name => "Vehicle", :foreign_key => "bus_id" 

If you have car_id as the foreign key. then you can ignore mentioning it in the model. 

Cheers




On Sun, Sep 28, 2014 at 6:40 AM, Paolo Wang <paulwangzy@gmail.com> wrote:
Hi to all.

I am working for a translation agency and I have the task to create an auto-estimate system and ordering/invoicing administration system. I am stuck on how to manage the language pairs.
I created a Language model with the language name and a LanguagePair with a source language, a target language and a rate per words attributes. I tried with:

LanguagePair
belongs_to :source, :class_name => "Language", :foreign_key => "source_id"
belongs_to :target, :class_name => "Language", :foreign_key => "target_id"

and also by replacing the source and target in the LanguagePair with a string type and loading it with a Language.all.permutation(2).to_a and eliminate the need for nesting.
In the end I will create a sort of cart and lineitem model and add the LanguagePair to the cart as a LineItem.

Is there a "best" way to do this maybe with a Language self-referential model?


thanks in advance

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c214ccfe-bc9a-4e5a-85fe-003a325fa2f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj9-TW7haqFzPBAqPsK1M5mWgJg5sUNaeHdR3%2B5CK6jN6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment