Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushing related model throws "invalid type for key" #132

Open
desmondhume opened this issue Jun 10, 2014 · 1 comment
Open

Pushing related model throws "invalid type for key" #132

desmondhume opened this issue Jun 10, 2014 · 1 comment

Comments

@desmondhume
Copy link

Hi,
I have two models, PaymentRequest, which has many reservations related to it through relation field.
Here is an example of how I'm doing it:

payment_request = PaymentRequest.first

payment_request.reservations 
    => [#<Reservation:0x007fc6bb2b84f8>, ...]

payment_request.reservations << Reservation.first
    => #<Reservation:0x007fc6bb223768>

payment_request.reservations.count
    => 2 

payment_request.save
    => false 

payment_request.errors.messages
    => {:"111"=>["invalid type for key reservations, expected relation<Reservation>, but got array"]} 

I'm doing as it's done in the tests from @mattvv fork, am i doing it wrong? There's another way to do it?

@mattvv
Copy link
Contributor

mattvv commented Jun 10, 2014

Hey Greg, if its one to many then we will save the reservations as an array
of pointers, this allows us to pull all reservations in one query rather
then two.

Matt

On Tuesday, June 10, 2014, Gregorio Setti notifications@github.com wrote:

Hi,
I have two models, PaymentRequest, which has many reservations related to
it through relation field.
Here is an example of how I'm doing it:

payment_request = PaymentRequest.first

payment_request.reservations
=> [#Reservation:0x007fc6bb2b84f8, ...]

payment_request.reservations << Reservation.first
=> #Reservation:0x007fc6bb223768

payment_request.reservations.count
=> 2

payment_request.save
=> false

payment_request.errors.messages
=> {:"111"=>["invalid type for key reservations, expected relation, but got array"]}

I'm doing as it's done in the tests from @mattvv
https://github.com/mattvv fork, am i doing it wrong? There's another
way to do it?


Reply to this email directly or view it on GitHub
#132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants