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

Belongs_to association should not be included automatically into save transactions #302

Open
wants to merge 6 commits into
base: edge
from

Conversation

@kvechera
Copy link

@kvechera kvechera commented Mar 14, 2020

The problem case example:

We have a class Note with belongs_to: :user, and User with has_many: :note.

A browser app creates some invalid Note object, note1, associates it with a user via note1.user = user, runs note1.save and gets some validation error. Then the app creates another Note object, note2, a normal one, associates it with the user via note2.user = user and runs note2.save. It gets a confusing state: the reactive_record tries to save both note1 and note2 in a single transaction, fails with rollback due invalid note1 and also refuses to save the note2.

A similar problem if we create and edit several Note objects associate to a user and save one of them - the backend will save them all.

It's an unexpected behavior, and accroding to https://guides.rubyonrails.org/association_basics.html: "Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either."

kvechera and others added 6 commits Mar 14, 2020
Belongs_to association should not be included automatically into save
transactions
records with equal non-nil id's are be equal, but if both id's are nil,
	we need to compare attributes
* ActiveRecord does not ignore primary key on an instance initialization, and if the primary key is present, the records has been saved with that key.
* While creating new instance of ActiveRecord, we do not need to load any data.
* The assignment of the attributes provided in the new arguments needs no conversion in the initilizer, the conversion should be done by setters themselves.
* The assignment of the attributes in the initializer has been rewritten using #assign_attributes
fixed #101 when ServerOp transmits errors to the client
the location, history, and match props provided by Router are needed to
be received directly from the native element so the components could use
them in all the situation - whether they are route children, a component
prop, or are rendered in the withRoute() context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.