limit of 30 on getRelatedRecordObjects sql query

A place for users and developers of the Xataface to discuss and receive support.

limit of 30 on getRelatedRecordObjects sql query

Postby rscales » Mon Sep 28, 2009 3:29 pm

Hi,

Thanks so much for this nice interface to mysql - it's really great.

I'm having trouble getting more than 30 rows back from a getRelatedRecordObjects sql query. My end goal is to import data from a csv but to only insert data if one of the columns in a row is new ('out' below), otherwise, perform an update to the existing row.

from my table delegate class:

function __import__csv(&$data, $defaultValues=array()){

$app =& Dataface_Application::getInstance();
$Rec_existing =& $app->getRecord();
//...snip... from standard import_csv function
foreach ( $rows as $row ){
list($in, $data, $new_out) = explode(',', $row);

$new = 1;
foreach ($Rec_existing->getRelatedRecordObjects('xouts') as $xout){
if($xout->val('out') == $new_out) {
$new = 0;
}
}
}
}
in relationships.ini:

[xouts]
__sql__ = "SELECT * FROM tableX ORDER by out"

The foreach statement only runs through 30 rows, even if the numbers of rows in tableX is >30. I successfully altered the display to display more than 30 rows, but this seems to have no effect on getRelatedRecordObjects. Adding a different LIMIT in the query, just gives an error as it coflicts with the LIMIT 0,30 already automatically added later.

Any clues, or potentially advice on a better way to do this? I am not sure how to leverage sql directly to find the matching values as I only know what to match from inside the import_csv function.

Thanks,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Postby shannah » Mon Sep 28, 2009 3:45 pm

getRelatedRecordObjects takes additional optional parameters.
http://dataface.weblite.ca/getRelatedRecordObjects

E.g.
$recs = $o->getRelatedRecordObjects('foo', 0, 1000)
will get up to the first 1000 related records.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby rscales » Tue Sep 29, 2009 5:39 am

Missed that in the documentation.
Thanks, import is working great now.

However, ss I am trying to filter my import to either add new entries or update existing ones, how would I enter new info into an existing record, rather than inserting a new one?

I have

Code: Select all
function __import__csv(&$data, $defaultValues=array()){

$app =& Dataface_Application::getInstance();
$Rec_existing =& $app->getRecord();
//...snip... from standard import_csv function
foreach ( $rows as $row ){
  list($in, $data, $new_out) = explode(',', $row);

  $new = 1;
  foreach ($Rec_existing->getRelatedRecordObjects('xouts') as $xout){
    if($xout->val('out') == $new_out) {
      $new = 0;
      if($xout->val('data') != $data) {
        $xout->setValues(
           array(
             'data'=>$data,
             'in'=>$in
            )
         );

    }
  }
  if($new){
    $record = new Dataface_Record('tableX', array());
    $record->setValues($defaultValues);
    $record->setValues(
       array(
         'out'=>$new_out,
         'data'=>$data,
         'in'=>$in
        )
      );
    elseif {  //update instead of create new record
      $record = $xout;
// gives an error in IO.php - call to a member function field
// on a non-object
    }
   
  records[] = $record;
}
}


So, my question is how do I take the new values of a csv for an existing record and perform an update, rather than creating a new DatafaceRecord? I'm afraid I am still struggling to understand the difference between records and objects. If I instead use getRelatedRecords for $xout, then I don't know how to grab ->val('out') from that.

Otherwise the generic import of new data is working great.

Thanks,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR

Postby rscales » Wed Sep 30, 2009 5:22 am

OK, never mind previous question, I discovered all the dataface io apis in the documentation and have everything working now.

Thanks,
Rich
rscales
 
Posts: 18
Joined: Mon Sep 14, 2009 1:10 am
Location: FR


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 14 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved