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

#new_record? is wrong if any data already exists #51

Open
mike-burns opened this issue Oct 6, 2018 · 0 comments
Open

#new_record? is wrong if any data already exists #51

mike-burns opened this issue Oct 6, 2018 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@mike-burns
Copy link

This issue occurs when connected to Fuseki:

class Article < Spira::Base
end

Article.new.save!
Article.new.new_record? # => false

(This is an attempt to pair down what is a more complex model on my end; hope it conveys the bug.)


Tracing through:

# A resource is considered to be new if the repository
# does not have statements where subject == resource type
def new_record?
  !self.class.repository.has_subject?(subject)
end
CONSTRUCT { _:g13426267119880 ?g13427767297260 ?g13427767296240 . } WHERE { _:g13426267119880 ?g13427767297260 ?g13427767296240 . } 

That blank node acts as a variable, so it matches so long as there is anything in the backing store. In other words, #new_record? produces true so long as any triple exists in the backing store.

Elsewhere:

    def materizalize
      if new_record? && subject.anonymous? && type
        # TODO: doesn't subject.anonymous? imply subject.id == nil ???
        @subject = self.class.id_for(subject.id)
      end
    end

Might be time to resolve that TODO.


This shows in Rails like so:

<%= form_for Article.new do |form| %>
<% end %>

#form_for eventually calls @article.id, which then crashes.

@gkellogg gkellogg added the help wanted Extra attention is needed label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants