Why can I not use In() inside FindOptions with TypeORM - typeorm

I'm currently trying to use In() to add a WHERE field IN() clause to my SQL query.
Right now my code looks like this:
this.repository.find({
where: {
id: In(['uuid-1', 'uuid-2']),
},
...options,
withDeleted: false,
});
I get a TypeScript error that says:
Type '{ id: FindOperator<string[]>; }' is not assignable to type 'FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]'.
Types of property 'field' are incompatible.
Type 'FindOperator<string[]>' is not assignable to type 'FindOptionsWhereProperty<NonNullable<Entity["id"]>>'

Related

Can relay fragment arguments be composed different from argument definition?

I have the following fragment definition
fragment LocationFragment_viewer on Viewer
#argumentDefinitions(userId: {type: "Int!"}) {
results: locations(
user_id: $userId
) {
...some_other_fragments
}
}
I want to change the argument from user_id to user_ids (which is just an array wrapping the id) in the GraphQL query, without changing the argument definition.
So I want something like:
fragment LocationFragment_viewer on Viewer
#argumentDefinitions(userId: {type: "Int!"}) {
results: locations(
user_ids: [$userId]
) {
...some_other_fragments
}
}
Is this even possible? In my case it is a bit hard to change the argument definitions, so trying to see if there is something easy to do without going that route.
Thank you!
I found that Relay has added support for this in https://github.com/facebook/relay/releases/tag/v8.0.0
This means arguments can be composed like:
inputs: [{query: $my_query}, $other_input, null, $another_input]
Exactly what I need!

Error: "type 'String' is not a subtype of type 'int'" when mapping a Dart Map

I have a map structured like so:
Map<dynamic, dynamic> optionsMap = {1: true, 2: false, ..., "totalCount": 1};
I explicitly declared the values as dynamic to avoid Dart's intelligent typing, even though it should handle this and make it dynamic.
I'm going to map it to provide a Map with the ending structure:
{1:{index1Name:index1Value}, 2:{index2Name:index2Value}...}
When trying to map this Map, using
Map optionsMap = optionsState.map(
(dynamic key, dynamic value) => MapEntry(key, [options[key], value]));
I get the following error:
type 'String' is not a subtype of type 'int'
I never strong typed an int. Why do I get this error?
What's the type of the options variable? If it is a list, the error may be caused by MapEntry(key, [options[key], value]) within the map function running at
options['totalCount']

How to reference enum type in entity sql

I have the following (simplified) Entity SQL query:
SELECT VALUE a
FROM Customers AS a
WHERE a.Status NOT IN { 2, 3 }
The Status property is an enumeration type, call it CustomerStatus. The enumeration is defined in the EDMX file.
As it is, this query doesn't work, throwing an exception to the effect that CustomerStatus is incompatible with Int32 (its underlying type is int). However, I couldn't find a way to define a list of CustomerStatus values for the IN {} clause, no matter what namespace I prefixed to the enumeration name. For example,
SELECT VALUE a
FROM Customers AS a
WHERE a.Status NOT IN { MyModelEntities.CustomerStatus.Reject, MyModelEntities.CustomerStatus.Accept }
did not work, throwing an exception saying it could not find MyModelEntities.CustomerStatus in the container, or some such.
Eventually I resorted to casting the Status to int, such as
SELECT VALUE a
FROM Customers AS a
WHERE CAST(a.Status AS System.Int32) NOT IN { 2, 3 }
but I was hoping for a more elegant solution.
Oooh, you are writing Entity SQL directly. I see... Any reason you aren't using DbSet instead of writing Entity SQL by hand? Could always do
var statuses = new [] { Status.A, Status.B };
var query = context.SomeTable.Where(a => !statuses.Contains(a.Status)).ToList();

How to specify sequence on non-id column in Grails?

I am trying to map a column in grails to a sequence, but this column is not the id.
Integer seqCol
I have tried the following code in static mapping, I'm basically just switching 'id' with 'colum'.
column name: "seqCol", generator: "sequence", params:[sequence:"SEQUENCE_NAME"]
This returns an error on save, saying that seqCol cannot be null which leads me to believe the mapping failed.
In order to change the name of the id property, you need to specify the name for the id property.
Integer seqCol
static mapping = {
id name: 'seqCol', column: 'seq_col', generator: "sequence", params:[sequence:"SEQUENCE_NAME"]
}

Grails g:select no selection

I have the following combobox:
<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
keys="${app.domain.enums.TicketType.values() }"
value="${ticketInstance?.ticketType}"
noSelection="${['null': 'Select One...']}"
/>
I've setup the following constraint for ticketType in command object
ticketType nullable: true, blank:true
TicketType is a very simple enum:
public enum TicketType {
QUESTION, SUPPORT, MAINTENANCE, NEW_FUNCTIONALITY, MALFUNCTION
}
And every time I don't setup some value for ticketType in my GSP I get the following error:
Failed to convert property value of type 'java.lang.String' to required type 'com.coming.enums.TicketPriority'
It's like in case of no selection g:select sets the value for "null" (string).
What am I missing?
Rather than using the 'null' literal, have you tried using an empty string as your noSelection attribute? e.g. noSelection="${['':'Select One...']}"? This may do a proper conversion to a true null value during data binding.
As your error says - you do have a string in your noSelection. This can't be converted to any of your enum values.
Remove the quotation marks of your null and it should work (it works for me with grails 2.0):
<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
keys="${app.domain.enums.TicketType.values() }"
value="${ticketInstance?.ticketType}"
noSelection="${[null: 'Select One...']}"/>
Under Rails 3.3.x, no variation of providing the "null" value worked. In the end, I resolved it by adding this line in to the controller+action before doing any use of the params:
// convert "null" strings to REAL nulls
params.account.each { it.value = (it.value == 'null' ? null : it.value) }
After that, the following worked fine:
account.properties = params.account

Resources