I've been trying to figure out how to do something like
SELECT * FROM domain WHERE config_id IN (1, 2, 3)
when using the nice findBy technique of Grails. Haven't really figured out how yet though, is it even possible? I was hoping for something like
Domain.findByConfigIn(configList)
but that doesn't work. Anyone knows how to do this, or even if it's possible?
Assuming your domain class has a field named configId, the following should do what you want:
Domain.findAllByConfigIdInList(configList)
Related
I have three class in my ontology
class babyAge (6+, 8+, 12+)
class taste (asam, manis, asin)
class food (recipe name)
i want to querying data food for babyAge (6+) and have taste (asam)
i use this code in my java program (i dont know if there are other code more simple than this one, if you know please tell me too) :
SELECT ?babyAge ?taste ?food
WHERE { ?babyAge mpasi:hasResep ?food.
?food mpasi:hasRasa ?taste.
FILTER regex(str(?babyAge),"6+").
FILTER regex (str(?taste),"asam")}
and i get my data. but when i execute that code in protege, i dont get anything. Can someone help me?
It's difficult to tell without seeing the ontology.
My first move would be to ensure mpasi is bound to the same value in the ontology and in your query - it might be a case of mismatched IRIs.
You might also want to try without filters and see if anything is returned.
I use the doctrine query builder to build my query.
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select(array('u'))->from('Account', 'a');
-- problem here
$qb->where('lower_unaccent(u.email) LIKE :search');
$qb->setParameter('search', $search['search'] . '%');
This works fine, but I would also like to apply the lower_unaccent function to the search parameter.
Is there a way to do this with the query builder?
Because when I do LOWER_UNACCENT(u.email) LIKE LOWER_UNACCENT(:search) I get the following error:
Error: Expected Doctrine\ORM\Query\Lexer::T_STRING, got 'LOWER_UNACCENT'
Even if I change LOWER_UNACCENT TO LOWER, I get the same error message.
You have to use $qb->expr()->lower('u.email') and $qb->expr()->lower(':search'). To create the "LIKE" pass those as arguments to $qb->expr()->like().
There doesn't seem to be a unaccent method though, but maybe there is a way to customize this. Let me know how it went.
EDIT:
Looking into lower()'s code, it seems like you can use any function you want like this:
new Expr\Func('LOWER', array($x));
By default, I'm pretty sure you can't do that.
lower_unaccent is not standard SQL, and as far as I can see, not supported by Doctrine.
What you can do is extend DQL with user-defined functions, which will do whatever you want. It is not so hard to implement. Here is some documentation:
http://docs.doctrine-project.org/en/2.0.x/cookbook/dql-user-defined-functions.html
http://docs.doctrine-project.org/en/2.0.x/reference/dql-doctrine-query-language.html#adding-your-own-functions-to-the-dql-language
I'm new to Django and I have a BIG problem. I don't like the "url pattern" philosophy of Django.
I don't want my pages to look like
http://domain.com/object/title-of-object
I want
http://domain.com/title-of-object
and of course I will have more than one type of object.
Is there an elegant way to achieve this with Django (not using hard-coded urls)?
Thanks!
Ever wondered that, if what you want to do seems so hard to acheive, you're doing it wrong? What is so wrong with /foo/name-of-foo/ ?
I'm trying to imagine your use-case and wondering if you need 'human' URLs for only a handful of pages. If so, it would work to go with the /foo/slug-for-foo/ approach but then use the django.contrib.redirects app to support hand-written URLs that redirect to the saner, more RESTful ones?
It is possible. You'll have to create one catch-all URL pattern, for which you'll create a view that will search all possible object types, find the matching one, and process and return that. Usually, this is a bad idea.
I would like to develop a web service with dynamic urls.
A common url pattern with named groups would be something like this:
(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive')
For my purpose I need a little more dynamic, because I don't know the number of groups from the beginning.
E.g. possible urls could be:
articles/post/comments
articles/post/author
article/post/
...
I could use something like this:
(r'^(?P<cat1>)/(?P<cat2>)/$', 'module.views.function')
(r'^(?P<cat1>)/(?P<cat2>)/(?P<cat3>)/$', 'module.views.function')
(r'^(?P<cat1>)/(?P<cat2>)/(?P<cat3>)/(?P<cat4>)/$', 'module.views.function')
..
and so on. Is there a smarter way to do this? Thanks in advance!
Wait if you only have 1 article then you want it to be article/post/, otherwise you want it to be articles/post/?
Since URLs are just regular expressions you could do something like
(r'^articles?/post/$', 'some_view')
the ? tests either 0 or 1 of s.
But fundamentally your URLs don't seem to make sense, when you write articles/post/comments, it sounds like you want to post comments on all articles? Same with article/post/, what does that mean? Which article are you trying to post (you only have one and at most one)?
Typically URLs look like articles/5/post/comments, which would mean "I want to post comments on article with a pk of 5".
Sorry if my answer didn't help. I guess I didn't really understand your question.
Was wondering if there's anything like ruby's .send for htmlbars. Been trying to search for it, but can't seem to find a proper answer. Here's what I want to do:
{{"name-of-helper" arguments}}
As simple as this. Is there any trick under it to achieve this effect?
There is no built-in one or supplemented one but if you need it you can write one for yourself.
Ember includes "component" helper which allows you to dynamically build component - it's not exactly the same, but might suit your needs.