Skip to content

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

Description

@mike-burns

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions