EPrints Technical Mailing List Archive

Message: #02516


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: Understanding how data objects link


On 15/01/14 09:39, Ian Stuart wrote:
When I use the code, I start with a user_id, and want to get the list of
postcards associated with that user, so I have code thus:

    # Before we do anything - we need to get the subscriber object
    my $subs_ds = $session->get_repository->get_dataset("subscriber");
    my $subscriber;

    { # Localise this search
      my $searchexp = EPrints::Search->new(
        session     => $session,
        dataset     => $subs_ds,
      );
      $searchexp->add_field( $subs_ds->get_field("userid"), $user_id );
      warn $searchexp->render_description->toString;
      my $results = $searchexp->perform_search;

      if ($results->count) {
        my @records = $searchexp->perform_search->slice(0,1); # Get
records from position 0, for a count of 1 records
        $subscriber = $records[0]
      } else {
        $subscriber = EPrints::DataObj::Subscriber->create( $session,
{userid => $user_id }, $subs_ds );
      }
    }

    # Having got a subscriber object, lets get a list of postcards they have
    # Postcards are 1 email address and some number of repositories
    warn "got subscriber " . $subscriber->get_id . "\n";
    my $postcards = $subscriber->get_value( 'postcards' );

This code successfully returns a matching "Subscriber", however the
final line in that code is causing me problems... I get the error

    dataset postcard has no field: datasetid

I have double-checked my code against that of EPrints::DataObj::EPrint
and EPrints::DataObj::Document - neither of them have a datasetid field,
and my own objects are creating records in exactly the same way!

if I add the following code above the sample given, I successfully get the response that eprint ID 86126 has 1 document:

  my $eps_ds = $session->get_repository->get_dataset("eprint");
  my $ep;

  { # Localise this search
    my $searchexp = EPrints::Search->new(
      session     => $session,
      dataset     => $eps_ds,
    );
    $searchexp->add_field( $eps_ds->get_field("eprintid"), 68126 );
    warn $searchexp->render_description->toString;
    my $results = $searchexp->perform_search;

    if ($results->count) {
my @records = $searchexp->perform_search->slice(0,1); # Get records from position 0, for a count of 1 records
      $ep = $records[0]
    }
  }

  # Having got a subscriber object, lets get a list of postcards they have
  # Postcards are 1 email address and some number of repositories
  warn "got eprint " . $ep->get_id . "\n";
  my $documents = $ep->get_value( 'documents' );
  warn "Got " . scalar @{$documents} . " documents\n";

This seems to confirm I've got something wrong in my packages.... but /what/ and /where/ is the question...

--

Ian Stuart.
Developer: ORI, RJ-Broker, and OpenDepot.org
Bibliographics and Multimedia Service Delivery team,
EDINA,
The University of Edinburgh.

http://edina.ac.uk/

This email was sent via the University of Edinburgh.

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.