Order the result of findDependentRowset does not work - database

I'm using the findDependentRowset() of the Zend-Framework. Here, I want to define some selection settings like ORDER or LIMIT.
The examplecode I've found doesn't work at all for me :-(
$table = new MyTable(); // extends Zend_Db_Table
$row = $table->fetchAll()->current();
$rowset = $row->findDependentRowset(
'table',
$table->select()->order('von ASC')->limit(1)
);
First thing is, that the select() method is not defined here. I have to use getAdapter() to be able to use this method.
Next, I get a warning:
No reference rule "SELECT ORDER BY `von` ASC LIMIT 1"
How can I fix this?
Thank you very much!!

Check the API docs for Zend_Db_Table_Row_Abstract - the Zend_Db_Table_Select should be passed in as the third parameter, not the second.

Related

Can I use same param name multiple times in the URL for codeigniter-restserver?

http://example.com/api/transfer/transfers/code/456/code/234
When using $this->get('code') on a url like above I expect the REST library to return an array or a list of the codes.
Instead it returns the last one.
Is there a way to return both values in a list, or is there another recommandation for formating the URL.
Thank you
I know it has been long since you posted the question. However it could help other people looking for the same thing.
Assuming that transfer is your controller and transfers is the function, another way to format your url could be:
http://example.com/api/transfer/transfers?code[]=456&code[]=234
This was you perform $this->get('code') you'll get an array back.
If you are creating the url via code then you may use http_build_query(). It handles the necessary escaping. It means it will replace [ for %5B and ] for %5D, in this case.
The code would be like:
$codes = array(456, 234);
$query = http_build_query(array('code' => $data));
$url = 'http://example.com/api/transfer/transfers?' . $query;

cakephp find method not working

I know this is very silly question but here I am not getting any error.
Bellow query working fine
$data=$this->Test->query('SELECT * FROM tests where report_id=85');
But same query in find method are not working
$condition=array('Test.report_id'=>85);
$data=$this->Test->find('all',array('condition'=>$condition));
find statement in cakephp should be
$condition=array('Test.report_id'=>85);
$data = $this->Test->find('all',array('conditions'=>$condition));
Cakephp find statement error in 'codintion'
You should try this
$data=$this->Test->find('all',
array('conditions'=>
array('Test.report_id'=>85)
)
);
please replace condition to conditions
You made Typo.And lets understand why 's' is used.
There can be 100 conditions in an array , Not only one , so its conditions
$conditions=array('Test.report_id'=>85);
$data = $this->Test->find('all',array('conditions'=>$conditions));
And another thing -> Always use $conditions as variable naming convention because you never know there are 1,2, or 1000 conditions .

Change Value of ParamInfo after adding to DynamicParameters?

I'm calling a stored proc in a foreach loop and would like to change the value of one of the parameters on each iteration. Currently, there doesn't seem to be any way to access the parameters once they've been added to DynamicParameters although from reading the source, I can see that DynamicParameters does keep an internal Dictionary. Any reason why this isn't public or if there's another way to get at the ParamInfos to change values?
Update
What I have currently:
foreach ( var fooID in fooIDs )
{
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add( ParameterNames.BarID, barID );
dynamicParameters.Add( ParameterNames.FooID, fooID);
connection.Execute( ProcNames.MyProc, dynamicParameters, commandType:CommandType.StoredProcedure );
}
Re-Add the parameter.
// Call Add() with new values.
dynamicParameters.Add(ParameterNames.BarID, differentBarID);
There is no real reason DynamicParameters is so secret about what it does, the ParamInfo class could be exposed and I would be happy to provide proper iteration/modification properties and/or methods. If you feel like you would like to pitch in, please submit a patch.
In the mean time you can simply implement IDynamicParameters which is the trivial interface we use to dispatch this to the underlying command, in your app. You can use DynamicParameters as a starting point.

why does gql query result cause exception when calling get()

I am attempting to retrieve an entry from my datastore with this:
query = UserData.gql("WHERE mDeviceId = :1", id)
Utils.log("my Object:" + str(query))
entry = query.get()
It just so happens that the variable 'id' doesn't even exist (typo), so I know how to fix this, but I don't understand why the result I get won't let me call get() on it. When I do, I get the error:
Exception: Unsupported type for property : <type 'builtin_function_or_method'>
Normally I just check if entry == None to see if I get no results. Does anyone know why this occurs and if I should be doing my checks for None differently, in case I have such typos in the future?
A variable named id is not defined in your code, so it passes the builtin function id, and QL complains that it's getting a function when it expected a value (integer?).
Check to make sure you're assigning id a value before you use it.
Even better, don't shadow builtins with your own variables-- it'll cause confusing errors like this. :-)

how to force drupal function to not use DB cache?

i have a module and i am using node_load(array('nid' => arg(1)));
now the problem is that this function keep getting its data for node_load from DB cache.
how can i force this function to not use DB cache?
Example
my link is http://mydomain.com/node/344983
now:
$node=node_load(array('nid'=>arg(1)),null,true);
echo $node->nid . " -- " arg(1);
output
435632 -- 435632
which is a randomly node id (available on the system)
and everytime i ctrl+F5 my browser i get new nid!!
Thanks for your help
Where are you calling this? For example, are you using it as part of your template.php file, as part of a page, or as an external module?
Unless you have this wrapped in a function with its own namespace, try naming the variable differently than $node -- for example, name it $my_node. Depending on the context, the 'node' name is very likely to be accessed and modified by Drupal core and other modules.
If this is happening inside of a function, try the following and let me know what the output is:
$test_node_1 = node_load(344983); // Any hard-coded $nid that actually exists
echo $test_node_1->nid;
$test_node_2 = node_load(arg(1)); // Consider using hook_menu loaders instead of arg() in the future, but that's another discussion
echo $test_node_2->nid;
$test_node_3 = menu_get_object(); // Another method that is better than arg()
echo $test_node_3->nid;
Edit:
Since you're using hook_block, I think I see your problem -- the block itself is being cached, not the node.
Try setting BLOCK_NO_CACHE or BLOCK_CACHE_PER_PAGE in hook_block, per the documentation at http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_block/6
You should also try to avoid arg() whenever possible -- it's a little bit of a security risk, and there are better ways to accomplish just about anything arg() would do in a module environment.
Edit:*
Some sample code that shows what I'm referring to:
function foo_block ($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0] = array(
'info' => 'I am a block!',
'status' => 1,
'cache' => BLOCK_NO_CACHE // Add this line
);
return $block;
case 'view':
.....
}
}
node_load uses db_query, which uses mysql_query -- so there's no way to easily change the database's cache through that function.
But, node_load does use Drupal's static $nodes cache -- It's possible that this is your problem instead of the database's cache. You can have node_load clear that cache by calling node_load with $reset = TRUE (node_load($nid, NULL, TRUE).
Full documentation is on the node_load manual page at http://api.drupal.org/api/drupal/modules--node--node.module/function/node_load/6
I have had luck passing in the node id to node_load not in an array.
node_load(1);
According to Druapl's api this is acceptable and it looks like if you pass in an array as the first variable it's loaded as an array of conditions to match against in the database query.
The issue is not with arg(), your issue is that you have caching enabled for anonymous users.
You can switch off caching, or you can exclude your module's menu items from the cache with the cache exclude module.
edit: As you've now explained that this is a block, you can use BLOCK_NO_CACHE in hook_block to exclude your block from the block cache.

Resources