Zend db table find just like fetchRow - zend-framework

I´m using find() to retrieve a value from the database, but It returns an array with the objects, I would like that it return to me just the object like fetchRow returns, is there any change or similar thing to do?
Thanks, and best regard´s.

Well, It was so simple, for those that are in doubt, the solution is:
Zend_Loader::loadClass('News');
$db = new News();
$row = $db->find($id)->current();
That´s it, thanks.

Related

Laravel Eloquent query similar to findorfail

I would like to look up and return an object referenced by a different column to that of id.
As far as I know there isn't another method similar to Task::findOrFail($id) but that can reference another field. For example:
Task::findOrFail('column_name' = 'column_data');
I'm currently using
Task::where('tid' , '=', $tid)->first();
Is this possible?
Maybe you can use the firstOrFail() function of Laravel.
Task::where('column_name', '=' ,'column_data')->firstOrFail();

FindBy property in TYPO3 Extbase MVC is not working

I'm unable to run the FindBy magic function property in Extbase MVC
$title=array(0 =>'Books Day');
$each_event=$this->eventRepository->findByTitle($title);
$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .
How do I make this work?
I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(
I'm using TYPO3 6.1 and extension builder.
The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?
The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:
$foo = $query->execute()->toArray();
By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:
$result = $this->myRepository->findAll();
Try
$each_event=$this->eventRepository->findByTitle($title)->toArray();
Reference to the QueryResult.
As said in the documentation, it returns a QueryResultInterface|array.
As a consequence you have to loop over the result like this:
foreach($each_event as $single_event) {
$single_event->getProperty();
}
If you are sure that it returns only one single value you could also access it by the index 0:
$each_event[0]->getProperty();

how to create a Zend_Db_Table_Select through a string query php

I have been taking a look, for if there any way to create a Zend_Db_Table_Select or Zend_Db_Select instance with a literal sql query. I mean, I've got a complex query and I want through this query create an object of that one.
I have been reading the docs for this classes and I didn't find anything. I guess that this is not possible.
Do you know something about it?
Thank you very much.
I think your best bet would be to write this in your model:
public function customQuery ($table, $id) {
return $this
->getDefaultAdapter()
->query("SELECT * FROM ? WHERE id = ?",
array($table,$id)
)
->fetchAll()
;
}
and also one more link would be very useful to you

How to compare 2 mongodb collections?

Im trying to 'compare' all documents between 2 collections, which will return true only and if only all documents inside 2 collections are exactly equal.
I've been searching for the methods on the collection, but couldnt find one that can do this.
I experimented something like these in the mongo shell, but not working as i expected :
db.test1 == db.test2
or
db.test1.to_json() == db.test2.to_json()
Please share your thoughts ! Thank you.
You can try using mongodb eval combined with your custom equals function, something like this.
Your methods don't work because in the first case you are comparing object references, which are not the same. In the second case, there is no guarantee that to_json will generate the same string even for the objects that are the same.
Instead, try something like this:
var compareCollections = function(){
db.test1.find().forEach(function(obj1){
db.test2.find({/*if you know some properties, you can put them here...if don't, leave this empty*/}).forEach(function(obj2){
var equals = function(o1, o2){
// here goes some compare code...modified from the SO link you have in the answer.
};
if(equals(ob1, obj2)){
// Do what you want to do
}
});
});
};
db.eval(compareCollections);
With db.eval you ensure that code will be executed on the database server side, without fetching collections to the client.

How to get whole index in ZEND Lucene?

Hi I am looking for a way to get the whole index if my query is nothing.
My lucene is a picture of my database without some unwanted content, like expired annonces...
So I would like to use only lucene to get annonces, and for that I need a way to get the whole index.
Any ideas?
thanks!
This is not the answer but something wich works for me:
Using an indexKey like is_indexed, always true.
I am adding "is_indexed:1" to my query and it works...
If you have something else, let me know!
I tend to use a field which is named after the index such as:
$oDoc->addField(
Zend_Search_Lucene_Field::keyword(
'index',
'availability'
)
);
Then the term query will return all fields. It's not pretty but it works fine.