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
Defining relationship between tables #18
Comments
It sounds like you might be expecting the model to load the You'll need to explicitly load the associated data you need. I wrote up a quick example using your mappers. The important part is line 57, where we eager-load the accounts for the retrieved user. The great thing about this is that we can pass in either a single object or an array and it will load all of the accounts for all of the users in a single query. It's kind of like ActiveRecord's I need to improve (or, in a lot of ways, write any) documentation for this. If only it were as fun as talking about the project … ;-) |
Indeed your gist is working well (of course). I don't know what I am doing wrong my code is 'similar to yours' but I have only one table. At least I know it is working so the issue is on my side (of course again :) ) Thanks a lot for the help. |
Yep. There's a mapper DSL method for that called Perpetuity.generate_mapper_for Customer::User do
collection 'User'
attribute :name, type: String
# etc...
end |
I totally forgot to respond to the thing about only having one table. Can you show me the code where you're inserting the objects into the DB? |
I think the problem was because my entity was using virtus. By removing it, it creates a second table as expected. Awesome for the |
Hmm, Virtus shouldn't break it — I've tried to ensure compatibility between the two libraries. Can you post your models as you had them with Virtus and show how you were instantiating them so I can see if I can reproduce the behavior? I just want to make sure it's not a bug in the serializer, and if it's a bug in Virtus we can let solnic know. |
Yes sure, see this gist: https://gist.github.com/alaibe/bbe2c256b92b9dc66955 I just reproduce it. Let me know if it works on your side |
You can see at the end of the gist the value of account is nil and there is no Customer::Account table in pg |
It looks like it's got something to do with the Perpetuity automatically assigns the id based on what the DB adapter returns as a result of its |
Found it. This is indeed a Perpetuity bug. The mapper relies on |
Fixed in jgaskins/perpetuity@5a04bdd and released Perpetuity 1.0.1. |
Hi,
It might be stupid but I can't succeed to define association (not embeded) using the perpetuity-postgres gem.
Here is my mappers:
If I inspect the db I can see a field with type json for accounts instead of seeing a second table.
Any Idea?
Thx
The text was updated successfully, but these errors were encountered: