How to put a foreign field in a where clause?

88 views
Skip to first unread message

Eric Maicon

unread,
Aug 6, 2013, 8:17:53 PM8/6/13
to activejd...@googlegroups.com
Sorry if it's a repeated question, but i really didn't find this at the internet....

how can i do this?

Entidade.where("pessoa.somefield", someField).limit(totalPerPage).offset(offset).include(Pessoa.class).toMaps();

Thanks 

Igor Polevoy

unread,
Aug 19, 2013, 1:31:53 AM8/19/13
to activejd...@googlegroups.com
just saw this, apparently Google is sending emails from this group to Spam folder on... Gmail - go figure. 

this:

Entidade.where("pessoa.somefield = ?", someField).limit(totalPerPage).offset(offset).include(Pessoa.class).toMaps();

will include a foreign key by default if there is a one to many or many to one relationship between Entidade and Pessoa. 

No need to add anything else. 

tx

Maxime Naus

unread,
Aug 27, 2015, 10:29:18 AM8/27/15
to ActiveJDBC Group
Hello,

Is this still working the same way on the current version?


I am trying a similar instruction and it does two queries and not a join between the tables:
The first one is a select * on the table Entidade.
The second one a select... in(" `IDs` of Entidade table returned by the first query").

parameters in the where() method are only applied to the first query so it generates an error as the field "pessoa.somefield" does not exist in the table Entidade.


My goal is to get data from both tables but filtered by where() when I do:  entidades.toJson(true);  (entidades is the list returned by the previous instruction)


Thx in advance.

Igor Polevoy

unread,
Aug 27, 2015, 11:54:52 AM8/27/15
to ActiveJDBC Group
According to documentation: http://javalite.io/lazy_and_eager#improve-efficiency-with-eager-loading it will in fact generate two queries and not a join. 

tx

Maxime Naus

unread,
Aug 28, 2015, 5:26:38 AM8/28/15
to activejd...@googlegroups.com
OK, thank you for your answer!
I tames your framework gradually.

Br,
Maxime


--
You received this message because you are subscribed to the Google Groups "ActiveJDBC Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activejdbc-gro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages