-
Notifications
You must be signed in to change notification settings - Fork 614
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
has_many associations don't save with recursive: :true #247
Comments
@rhannequin ...see @allenwlee's findings in issue #231 (short answer is to add One problem I've found with this, in a common use case (dropped 2nd problem as it should be its own issue): If there's also a model that has a |
also, make sure to use the latest version (0.11.0 was throwing off |
@JHFirestarter Thank you for your answer. Unfortunately I'm facing the same results. Using the same example project from the wiki, I updated the gem version from Github (now class Book < ActiveRecord::Base
has_many :reviews, inverse_of: :book, autosave: true
end The task return is still the same, even if I added
|
@rhannequin do you also have |
@JHFirestarter I did not but just did and unfortunately it's still the same. My rake task hasn't changed and my only two models look like this: class Book < ActiveRecord::Base
has_many :reviews, inverse_of: :book, autosave: true
end
class Review < ActiveRecord::Base
belongs_to :book, inverse_of: :reviews, autosave: true
end Thank you again for your help. |
Just making sure |
Yes sorry, just updated my previous comment, the syntax is supposed to be correct. |
@rhannequin np. only difference I can tell between what you and I have is (a) the db (I'm sure postgresql) and (b) potentially how we generated associations (i.e. I generated a review migration containing the line Models contain: I'm out of (limited) ideas after that! |
@JHFirestarter My project will be on PostgreSQL but I'm using Sqlite3 for this example as I wanted to only test this multi-level feature of the gem. My schema has been generated from the migrations mentionned above in my first comment, and looks like this: ActiveRecord::Schema.define(version: 20160302142135) do
create_table "books", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "reviews", force: :cascade do |t|
t.string "name"
t.integer "book_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "reviews", ["book_id"], name: "index_reviews_on_book_id"
end I should mention that I tested the association in the console, it works when I create a Thank you again. |
@rhannequin the :recursive option currently only works for Postgres. The documentation should be updated to make that clear. As of version |
@jkowens Thank you, that makes sense now. Is there any work in progress to cover Sqlite3 as it may be used on test and development environments? Or maybe is there a feature inside this gem that makes it impossible to work for Sqlite? |
I believe this feature could possibly be implemented for sqlite3, but I don't know if there is currently any work in progress to make that happen. |
@jkowens and what about mysql2 adapter? Looks like :recursive option doesn't work for it |
@yuri-karpovich you are correct this does not work for mysql2 either. |
If am reading this thread right the desired outcome is that the |
@zdennis that is how I understand it. In #104 @robmathews provided suggestions on how to possibly implement this functionality for SQLite and MySQL. |
@rhannequin with the 0.14.0 release sqlite3 now supports recursive import. |
@jkowens Thank you, I should be able to test it soon. |
@jkowens and what about mysql? |
@yuri-karpovich sorry I should have added a comment to this before closing. Unfortunately there currently does not seem to be a good way to implement this feature for MySQL. See PR #279 for some more details. Unless MySQL implements an option to return inserted/updated IDs like PostgreSQL, we will not be able to make this work in a reliable way. |
@jkowens thank you for information. |
Hello,
First, thank you very much for this gem, it is much appreciated every day from casual to complex data imports.
I am having troubles with the multi-level feature, when trying to import models with associations. I tried to follow the multi-level example this way:
I created a blank app with two models:
Then I added the association to the
Book
model:I created a basic rake task with the same code as the example, to insert books with one review in each, and checking at the end if everything went good:
What I have in return shows that the books were inserted but not the associated reviews:
I don't know if my way of inserting associated models in database is wrong or if the multi-level feature has an issue, I thought it was the best place to warn about this behaviour has @sferik 's PR #230 (thank you for that btw) was supposed to fix it.
This test was run on Ubuntu 15.10 with:
rails
v4.2.5.1activerecord
v4.2.5.1sqlite3
v1.3.11activerecord-import
from Github (at master@df866a4)This post is a duplicate from my comment on #243.
Thank you.
The text was updated successfully, but these errors were encountered: