Find or create (upsert) functionality in Doctrine 2 - doctrine

Does Doctrine 2 have upsert functionality built in? It doesn't seem to, but I wasn't able to find a definitive yes-or-no answer.
If it does, I would of course be interested to see an example and/or some documentation.

I believe I found the answer. As of today (10/15/2012), there's an open "add upsert support" issue for Doctrine. I assume that this ticket wouldn't still be open if Doctrine 2 did have upsert support, so I guess there's my definitive answer.

Upsert is already present in Doctrine.
Using the query builder, you have to set findAndUpdate() and returnNew() if you want to return the document. Set upsert() and you're ready to go.
For example:
$documentMannager->createQueryBuilder('App\Domain')
->findAndUpdate()
->returnNew()
->field('_id')->equals($id)
->field('page')->equals($page)
->field('count')->inc(1)
->upsert()
->getQuery()
->execute();
This is the way i implement a bucket pattern.

Related

Subquery in JQuery QueryBuilder

I am going to use the JQuery Query Builder plugin in my project. I want to know how query will generate for relational table.
For example, I have two tables user and user_emails. I want to filter those users which have an email address. To get this result, I have to use subquery on user_emails table. Has that been possible by using this plugin? In the demo, I have not found this case.
Your question is vague. Do you want to build conditions in the jQuery-QueryBuilder for "All users with emails"? You also want the jQuery-QueryBuilder to look and return something like the following?
After you clarify the community can point you in the right direction.

Live Search Using Laravel

I can't find any good plugins for a live search using Laravel, does one exist? I've found a few jQuery autocomplete plugins but I'm looking for something like this: https://github.com/iranianpep/ajax-live-search
I tried implementing the above yesterday (for about 10 hours) and couldn't get it to work due to the MySQL queries they use vs Laravel's implementation
any thoughts or information is appreciated
I also tried using a large Laravel query to receive data (I want to search more than one column) but using the
User::where('name', 'like', $query)->orWhere('username', 'like', $query)->etc.
format didn't even match the name for me. Is there such a thing as a more advanced algorithm to search?
Thanks
Zach
Laravel Scout is your answer.
Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.
Currently, Scout ships with an Algolia driver; however, writing custom drivers is simple and you are free to extend Scout with your own search implementations.
I would personally recommend Algolia as well, as it is very sophisticated, has a free entry level, and is better than any search you could come up with by yourself.
You can set the ranking yourself in their backend, it will regard typos made in your search, and so much more. Plus it is cloud powered!
With Laravel Scout any searching is made a breeze just like:
$users = App\User::search('Chris')->get();
What's really cool:
$users = App\User::search('Chrs')->get();
Both $users return the same results. Even with a typo.
For more information you can read up in the official Laravel Scout documentation.
If you are a member of Laracasts, check out these screencasts. And even if you are not, it's really cheap and you will learn a lot on Laravel Scout and live search!

Rename an index in Laravel 5

I want to rename an index in Laravel 5.
In a previous migration a column was created for table named a like so:
$table->unsignedInteger('foo')->index('blah');
I want to rename the index so that it uses the default Laravel notation.
i.e. I want to rename the blah index to a_blah.
I know how to rename a normal column, like so:
$table->renameColumn('from', 'to');
But the documentation does not mention how to rename indexes.
How can I do this?
UPDATE
It seems that Laravel does not support this natively. Please upvote the issue:
https://github.com/laravel/internals/issues/443
Laravel 5.6 now supports renaming indexes:
$table->renameIndex('from', 'to')
https://laravel.com/docs/5.6/migrations#renaming-indexes
Old Answer for Laravel <= 5.5
As #KuKec mentioned, it seems Laravel does not have native support for renaming indexes. But you can use raw SQL. For example in MySQL it would be like so:
DB::statement('RENAME INDEX old_index TO new_index');
This would also likely be more efficient than dropping and re-indexing (especially on large databases).
I have also created an issue for the feature request so this is better supported. Please upvote it here: https://github.com/laravel/internals/issues/443
I think Laravel doesn't support any method for renaming index, you should drop the old index blah
$table->dropIndex('blah');
and make new one with desired name a_blah.
$table->index('foo', 'a_blah');
You should first:
$table->dropIndex('your_full_name_index')
then do
$table->index('new_index_name')

Fixed or "frozen" columns in table inside Eclipse Scout

I am interesting into how implement "frozen" columns inside Eclipse Scout table.
I see solution with two tables https://www.eclipse.org/forums/index.php/t/99484/, but I am looking if anyone has different solution, or this is the only one.
Marko
You are looking at what Excel describes as freeze panes?
I afraid there is no support in Scout for this at the moment. You can file a change request in Bugzilla, but without any sponsoring (money or code contribution), it will be hard to implement this.
You can have a look at the approach chosen by Karsten Thoms for the RAP-UI: Scout tables with fixed columns. He uses a custom field (he has extended the default RAP table).
In my opinion, if we include this feature in Scout, it should be a property on each column (frozen = true / false) and not on the table.

How can I query all past versions of an object with eclipselink?

Well, by means of historical session, we can query an object at a specific time. But what I need is to query all the versions of that object..
The documentation points out that we can not do this.. But is there anyone that customize eclipselink for this behaviour?..
edit : well, this question has been asked at eclipselink forums. It seems that nobody interested in this question.
EDIT :
I have requested an enhancement request. If you want this enhancement, please vote.. Here is the link : https://bugs.eclipse.org/bugs/show_bug.cgi?id=333725
Here is the answer from eclipselink forum ..
There does not seem to be an easy way
to do this. Please log an enhancement
request and vote for it.
You can use a native SQL query for
this. You will need to set
"eclipselink.maintain-cache"="true" on
the query.
You could also map a separate class to
the historical table, and include the
start and end date in the object, and
the startDate as part of the Id. This
is really what you would want to do,
as querying the original class will
not give you access to the start and
end dates. You could use a
MappedSuperclass and have the current
and historical class subclass it and
use the different tables.

Resources