cakephp find('all') statement returns double entry - cakephp

I am working with a site using cakephp 1.3. Last month i have changed hosting service of the site. After that i am having a issue.
ie. I have bookings table in my DB. When i am using find() statement, bookings table returns double entry. I could not find why this is happening.
For example, I got the vehicle data of the particular place returns the below,
when i use 'recursive'=>2 in find('all') statement ,I got the following
**
Parking Location : Chennai Citi Centre 2W
Booking Date : 02/04/2013
Booking ID Transaction Type Vehicle No Check In Date Check Out Date
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
**
But when i use 'recursive'=>-1 in find('all') statement,I got the following
**
Parking Location :
Booking Date : 02/04/2013
Booking ID Transaction Type Vehicle No Check In Date Check Out Date
187994 Normal 7099 02/04/2013 18:31 02/04/2013 22:03
**
Here parking location is not coming. Its in providers table.
Please anyone help me to fix this

Normally I wouldn't recommend using anything other than recursive=>-1, and just use containable behavior when appropriate.
I can't really tell you why the first approach returns double entries without knowing the models associations, or having the exact find query you're using (are you doing a find() with the Bookings or the Parking or what else :S ?), but try and use containable and see if it works.
Something like... (I'm just going to assume how your models are called and how you're using find())
$this->Booking->find('all', array('conditions'=> array() ,//some conditions here
'recursive' => -1,
'contain' => array('Parking'));
After that, do a dump of the returned array to see if the output fits your needs. For more of containable behavior check here.

Related

How to use CALCULATE with LOOKUPVALUE and USERELATIONSHIP

I have three tables, one dim table called "ISO_ccy" only showing the ISO acronyms of currencies, one dim table showing the "home currency" of an entity ("entities") and another (fact) table ("trades") showing foreign exchange (FX) trades. The thing with FX trades is, they always have two currencies (ccy) involved, hence the latter table has two columns with currency ISO codes (and corresponding amounts). The two dim tables both only have one column with ISO ccy codes (the table "ISO_ccy" having distinct values only).
I now have one (active) relationship for currency 1 (ccy1) and one inactive for currency 2 (ccy2) between the "ISO_ccy" and the "trades" table. There is also an active relationship between "ISO_ccy" and "entities" tables.
I need to calculate the sum for each currency and each entity where the currency is not equal to the "home currency" of that entity.
Seems to be pretty straight forward for the ccy with an active relationship (ccy1):
Sum_Hedges_activeRelation:=
CALCULATE(
SUM([Amount_ccy1]);
FILTER(trades;trades[ccy1]>LOOKUPVALUE(entities[ccy];entities[name];trades[name]))
)
The filter expression ensures that only amounts are shown where the ccy of a trade is not equal to the "home" ccy of the entity.
Here, I'm getting the desired result.
Now I need to do the same with the inactive relation (ccy2).
This is what I tried:
Sum_Hedges_in-activeRelation:=
CALCULATE(
SUM([Amount_ccy2]);
USERELATIONSHIP(trades[ccy2];ISO_ccy[ccy]);
FILTER(trades;trades[ccy2]<>LOOKUPVALUE(entities[ccy];entities[name];trades[name]))
)
However, I only get an "empty" result.
I also tried to add "ALL(trades)" to the CALCULATE function. No results there as well.
So, I am a bit at a loss now, how I can make this work. Can you please help?
UPDATE 08 April 2019 with a solution:
I found a solution to my problem here:
sqlbi: USERELATIONSHIP in a Measure
Now my forumlar looks like this:
Sum_Hedges_in-activeRelation:=
CALCULATE(
CALCULATE(
SUM([Amount_ccy2]);
FILTER(trades;trades[ccy2]
<>LOOKUPVALUE(entities[ccy];entities[name];trades[name]))
);
USERELATIONSHIP(trades[ccy2];ISO_ccy[ccy])
)
This is slightly different from the solution provided (for a column related context) in the referenced article, as I omitted the ALL() instruction in the outer CALCULATE(). I could not explain, though...

how to pre-fill some parts of an access form?

New here, so be gentle with me. - edited to simplify
I'm trying to set up something in Access where:
user selects driver name and date
query finds stops along the driver's route
form opens with route stops (location details) filled in and user can add additional information (item picked up, weight of item)
all information gets transferred to a "Pickups" table, which has data on what was picked up, the weight, where (route stop) and by whom (driver).
I have stores A through H, and three drivers, Bob, Tom, and Jill. Bob’s route is stores A,B,C,D. Tom’s route is stores A,C,G,H, and Jill’s route is stores D,E,F,G. (I can't give real names/locations - work is very strict about privacy issues!)
Behind these are “Driver” Table, with driver name, ID, and truck info; and “Store” Table, with store name (A-H), address, phone number, and contact person.
We’re collecting all of the information about items picked up at each store into a “Pickup” table, with Fields: Date, Driver, Store, WeightOfFurniture, WeightOfBooks, WeightOfClothes
The user starts with the driver’s name and date, clicks a button, and this opens a form with the following fields:
Driver, Date, Store, WeightOfFurniture, WeightOfBooks, WeightOfClothes
with driver and date filled in based on the initial entry, and “Store” having all listings for a given driver’s route. So I select Bob and a date (11-12) and get a form with:
Name Date Store WtFurn WtBooks WtClothes
Bob 11-12 A
Bob 11-12 B
Bob 11-12 C
Bob 11-12 D
I can get the above information from a query without any problem, but I can't figure out how to (partially) fill the form with the query results (there will be multiple query results for a given route, so DLookup is not useful).
I think recordsets might be a way to go, but not sure how to do this. I'm very new at VBA, but am learning (the hard way!).
Any suggestions?
Thanks!
Use an INSERT INTO action query to insert those records into your Pickup table.
I can get the above information from a query without any problem,
This query is the SELECT FROM part for the INSERT query.
Then open your Pickup form, filtered for Driver, Date and Store that you just inserted.

How to Select a record in Access if it is not a duplicate value

Ok, from the title it seems to be impossible to understand, I'll try to be as clear as possible.
Basically, I have a table, let's call it 'records'. In this table I have some products, of which I store 'id', 'codex' (which is a unique identifier for a certain product in the whole database), 'price' and 'situation'. This last one is a string which tells me wether the product has just entered the store (in that case it is set to 'IN'), or it has already been sold ('OUT' in this case).
The database was not created by us, I HAVE to work with that although it is horribly structured... The guy who originally projected the database decided to register when a product's situation passes from 'IN' to 'OUT' in the following way: instead of UPDATEing the corresponding value in the table, he used to take the row of data with 'IN' as situation, and to DUPLICATE it setting, that time, 'OUT' as situation.
Just to sum up: if a product has not been sold yet, it will have one row of dedicated data; otherwise those rows will be two, identical except for the 'situation' field.
What I need to do is: select a product if (and ONLY if) there is no duplicate for it. Basically, I can (and should) look for a 'codex', and if I my Count(codex) ends up being >1, I do not select the row.
I hope the explanation of the process is clear enough...
I tryed many alternative (no, SELECT DISTINCT is not a solution): des anyone have an idea of how to do that? Because really, none of us three could come up with a good solution!
Here is the schema for the table, I hope it is sufficiently clear, and if not do not hesitate asking for more details.
Just as a reminder: the project is in (sigh...) VB.net, the database is in Microsoft Access (mdb).
I could not find a solution on StackOverFlow, I hope this is not a duplicate question! Thanks in advance for the help.
id codex price situation
1 1 2.50 IN
2 1 2.50 OUT
3 2 3.45 IN
4 3 21.50 IN
5 2 3.45 OUT
6 4 1.50 IN
To check if I understand what your problem is... In your example table you just want to get the lines with ID 4 a 6, right?
If is that what you want, and If you want only the not sold ones try this command
SELECT
*
FROM
records
WHERE
codex
not in
(
SELECT
codex
FROM
records
WHERE
situation ='OUT'
)

Criteria to get last not null record present

I have a daily record table where records are stored date wise. I am using hibernate criteria to access data. How do i get the last date till which records are present continuously (date wise continuity) by providing a date range. For example, say records are there from 21-09-2012 to 25-09-2012 , again from 27-09-2012 to 31-09-2012. I want to form a query using criteria to get record of date 25-09-2012 because for 26-09-2012 there are no records (by passing date ge 21-09-2012 and date le 31-09-2012) . I want to know the last date till which records are present continuously. Say the table has three fields - 1.recordId (AI) 2.date 3.Integer record.
Its not a proper solution to your question. But it may be scenario specific.
How about getting the data for a date range and show then on a calender. Change the color of date if the corresponding value is null.
I think HQL will be better way to this in Hibernate:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

strange appengine query result

What am I doing wrong in this query?
SELECT * FROM TreatmentPlanDetails
WHERE
accountId = 'ag5zfmRvbW9kZW50d2ViMnIRCxIIQWNjb3VudHMYtcjdAQw' AND
status = 'done' AND
category = 'chirurgia orale' AND
setDoneCalendarEventStartTimestamp >= [timestamp for 6 june 2012] AND
setDoneCalendarEventStartTimestamp <= [timestamp for 11 june 2012] AND
deleteStatus = 'notDeleted'
ORDER BY setDoneCalendarEventStartTimestamp ASC
I am not getting any record and I am sure there are records meeting the where clause conditions. To get the correct records I have to widen the timestamp interval by 1 millisecond. Is it normal? Furthermore, if I modify this query by removing the category filter, I am getting the correct results. This is definitely weird.
I also asked on google groups, but I got no answer. Anyway, for details:
https://groups.google.com/forum/?fromgroups#!searchin/google-appengine/query/google-appengine/ixPIvmhCS3g/d4OP91yTkrEJ
Let's talk specifically about creating timestamps to go into the query. What code are you using to create the timestamp record? Apparently that's important, because fuzzing with it a little bit affects the query. It may be relevant that in the datastore, timestamps are recorded as integers representing posix timestamps with microseconds, i.e. the number of microseconds since 1/1/1970 UTC (not counting leap seconds). It's also relevant that dates (i.e. without a time) are represented as midnight, i.e. the earliest time on that day. But please show us the exact code. (It may also be important to show the actual content of the record that you're attempting to retrieve.)
An aside that is not specific to your question: Entity property names count as part of your storage quota. If this is going to be a huge dataset, you might pay more $$ than you'd like for property names like setDoneCalendarEventStartTimestamp.
Because you write :
if I modify this query by removing the category filter, I am getting
the correct results
this probably means that the category was not indexed at the time you write the matching records to the data store. You have to re-write your records to the data store if you want them added to the newly created index.

Resources