relations between ir_attachment and mail_messages in odoo 8 - message

I tried to get relations between messages and ir attachment using psql, bu didn't find anything yet. i have message ids in mail_messages and attachment ids in ir_attachment. but i couldn't find which message has which attachment, like foreign key relation ship... any solution .

I have made my comments as below , kindly request you to find it as below it will help in your case:
What is the Relation Between ir.attachment and mail.message
Well ir.attachment and mail.message have Many2many Realtion.
You can visualize it in ODOO from here and from ir.model in ODOO view also.
For viewing this relation records look-up the table_name(message_attachment_rel) into pgadmin created by this relation or just connect with psql, type \c your_db_name and \dt .
In side the column1 you will find the Ids for mail.message(message_id) and in the column2 the Ids ir.attachment(attachment_id) .
I hope after visiting all these link your query will definitely solved.

Related

Error 42601 Inner join

I am using Postgres 9.6 and pgadmin 4.2 version.
I am getting error 42601 when executing the below query. can someone help in resolving the issues
Select EmpID, Name, address, Dept from Employee, Deptarment where Employee.EmpID = Deptarment.EmpID
I suppose error 42601 is Syntax error
And it seems that you happen to spell your table name wrong.
It would be better if you post the
Create statement of table.
Although, it looks like that you have misspelled the table department in that query.
It is always recommended to use alias in such case.
Try executing that statement by replacing Deptarment by Department
or you can use an Alias for the same
as
Select EmpID, Name, address, Dept from Employee as e, Department as d where e.EmpID = d.EmpID
(Assuming that you misspelled the Table Department in your Database)
Finally found the solution, need to put column names and tablenames under double quotes and then it works perfectly

Select join table fields in SOLR

I have a SQL query something like this
SELECT
P . ID,
P .code,
l.parent_id
FROM
properties P
LEFT JOIN locations l ON l. ID = P .location_id;
I want to convert this query to SOLR query. I can join two cores by below system
http://example.com:8999/solr/properties/select?q=*:*&fq={!join from=id to=location_id fromIndex=locations}p_id:12345
But I cant select the fields of locations core.How can I do this? Your valuable suggestion will be appreciated.
You can use subquery in the fl. Something like this fl=*,locations:[subquery fromIndex=locations]&locations.q={!terms f=id v=$row.location_id}
More info here https://lucene.apache.org/solr/guide/6_6/transforming-result-documents.html#TransformingResultDocuments-subquery
You can't. Solr does not support returning fields from both ends of an join. Solr is not a relational database, so you're usually better off trying to not use it as one.
Instead, index the information about each location to each property, and query based on that.
If any location info changes (which it turns out, usually happens very rarely), reindex the documents assigned that location.

Rails postgreSQL duplicate key

I have a Rails app that uses postgreSQL.
I recently did a backup of production and restored it to development.
When I try to add a Payment record in development, I get:
ERROR: duplicate key value violates unique constraint "payments_pkey"
DETAIL: Key (id)=(1) already exists.
Yet, there is only one record in the table with id=1 and the payments_id_seq has Current value = 1.
So, whey isn't Rails trying to add id=2 ??
Thanks for the help!
PS - is there a script or command in pgadmin to force the id_seq to be correct?
If you receive a PostgreSQL unique key violation error message ("duplicate key value violates unique constraint..."), probably your primary key index is out of sync, e.g. after populating the database.
Use
ActiveRecord::Base.connection.reset_pk_sequence!('[table_name]')
to fix the sequence for the users table.
Presumably whatever method you used to copy your database didn't update your sequences along the way, a standard dump/restore should have take care of that but if you copied things row-by-row by hand then you'll have to fix things using setval.
If you only need to fix the sequence for a table T, then you could do this from the console:
ActiveRecord::Base.connection.execute(%q{
select setval('T_id_seq', m)
from (
select max(id) from T
) as dt(m)
})
or you could feed that SQL to pgadmin. You'd repeat that for each table T.

Group by or Select Distinct with Rails, ActiveRecord, Heroku and PostgreSQL

I have a table of records;
Users: id, screen_name, tweet
I want to return a list of the users and group by the screen_name so that there aren't duplicate screen_names in the list.
#users = User.all(:group => "screen_name")
This works fine when using MySQL, but not when I push to Heroku, which uses PostgreSQL.
How can I get a similar set of results using PostgreSQL?
There seem to be a good few posts on this but I couldn't figure out an answer from the comments.
Unless screen_name is not a primary key you should add all columns in your group statement or aggregate them. But it looks like that you can't aggregate id or tweets ))
.group("id, screen_name, tweet")
You can also normalize your database. Put screen names to another table and you will be able to get desired data easily.

Updating joined queries with ADO

I have a select query that joins 3 tables to display information. If I want to update a field is do
ADOQuery.Edit.
<Set fields Values>
ADOQuery.Post.
I get the following error howwever 'Insufficient key column information for updating or refresing' and I'm not sure how to proceed.
Thank you.
Pieter
Try this OnCreate:
YourADODataSet.Properties['Unique Table'].Value := 'YourTable';
This will let the Engine send only one (instead of two) query from joined tables.

Resources