Как может я создавать новые записи с has_many: через и честь: условия?

Я попробовал это, и это работало:

String.Format("{0:d}", MyValue)
9
задан Eric 3 October 2009 в 21:13
поделиться

1 ответ

I believe that you have encountered a Rails bug. I tried the same thing on my box (2.3.4) and it gives me the same error which doesn't seem right at all. Additionally I also tried the work around of:

course = Course.first
course.observers << Student.create(:name => "Joe Student")
course.save

But this creates a membership with the observer field set to false!

The final ugly workaround I came up with was creating the Membershiprecord manually:

Membership.create!(:course => Course.first, :student => Student.first, :observer => true)

I've created a ticket for this and I'll be investigating further after breakfast.

EDIT: I have, as promised, investigated further and found if you change your :conditions Hash to an Array such as:

:conditions => ["memberships.observer = ?", true]

It works as intended. I also have a github repository with example code and instructions to duplicate.

7
ответ дан 4 December 2019 в 23:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: