On Thu, Jul 14, 2011 at 11:13 AM, Michael Pavling <[email protected]> wrote:
> On 14 July 2011 16:03, joanne ta <[email protected]> wrote: > > On Thu, Jul 14, 2011 at 10:41 AM, Michael Pavling <[email protected]> > wrote: > >> In Language, you have "belongs_to :name" (which is really Phrase), and > >> belongs_to :phrase. So you need a phrase_id field, and a name_id field > >> - one for each of the relationships. > > > > belongs_to phrase, I add it because the languageTest is complaining there > is > > no association with phrase. > > so that i added it to language model > > If you don't want it, take it out. > Change the "name" field to "name_id" for all our sakes.... > yes,, I did change it and it language table (DB) it changed the name => name_id in language model belongs_to :name_id, :class_name => "Phrase", :foreign_key => "name_id" in phrase model has_many :languages, :foreign_key => "name_id" it complains 1) Failure: test: belongs to and has many association should belong to phrase. (LanguageTest) [/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:324]: Expected Language to have a belongs_to association called phrase (no association called phrase). Expected block to return true value. 2) Failure: test: check has_many and belongs_to association should have many languages. (PhraseTest) [/usr/local/lib/ruby/gems/1.9.1/gems/shoulda-2.11.3/lib/shoulda/context.rb:324]: Expected Phrase to have a has_many association called languages (Language does not have a name_id foreign key.). Expected block to return true value. > >> In Phrase, you "has_many :languages", but language doesn't yet have a > >> phrase_id field. Or did you mean for this has_many to point at the > >> name_id field as foreign key? > > > > yes. I want to point the name_id as foreign key of phrase > > one phrase(id) can have many language (name_id/phrase_id) > > So do that then (how's Rails supposed to know that you've decided for > no reason not to use "phrase_id" as the foreign key field in > Language?!): > has_many :languages, :foreign_key => :name_id > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

