So I am using prisma and I am trying to get the count of votes on thread where the vote value is VoteStatus.down. I am following the docs here.
I am getting Type '{ where: { vote: "down"; }; }' is not assignable to type 'boolean'. when I do this:
await this.prisma.thread.findMany({
select: {
_count: {
select: {
votes: { where: { vote: VoteStatus.down } }
}
}
}
});
Here are my models in schema.prisma (note: I have modified for simplicity of the question):
model Thread {
id Int #id #default(autoincrement())
votes ThreadVote[]
}
model ThreadVote {
id Int #id #default(autoincrement())
thread Thread #relation(fields: [threadId], references: [id])
threadId Int
vote VoteStatus
}
enum VoteStatus {
up
down
}
I'm wondering if there is a bug in prisma? It seems to line up with the docs perfectly. Note that I am on Prisma 4.3.1.
Edit: I am now thinking it is because I have to add the filter relation count:
generator client {
provider = "prisma-client-js"
previewFeatures = ["filteredRelationCount"]
}
I essentially have 3 tables that I want to nest, 2 already work but I can't get hasManyThough to work.
My tables :
tablename : measurements
id
client_id (not important for now.)
tablename : measurement_data
id
measurement_id
measurement_field_id
data
tablename : measurement_fields
id
type_id (not important for now)
name
enabled
Heres my controller function :
public function index()
{
return JsonResource::collection(Measurement::with(['clients', 'measurement_data', 'measurement_fields'])->get());
}
My Model Measurement functions :
public function clients() {
return $this->belongsTo(Client::class, 'client_id');
}
public function measurement_field() {
return $this->hasMany(MeasurementData::class);
}
public function measurement_data() {
return $this->hasManyThrough(MeasurementField::class, MeasurementField::class, 'measurement_field_id', 'measurement_id');
}
My Model MeasurementData functions :
public function measurements() {
return $this->belongsTo(Measurements::class, 'measurement_id');
}
public function measurement_fields() {
return $this->hasOne(MeasurementType::class, 'type_id');
}
My Model MeasurementField functions :
public function measurements() {
return $this->belongsTo(MeasurementsData::class, 'measurement_field_id');
}
Whenever I fetch it I get this in console :
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'measurement_fields.measurement_field_id' in 'field list' (SQL: select `measurement_data`.*, `measurement_fields`.`measurement_field_id` as `laravel_through_key` from `measurement_data` inner join `measurement_fields` on `measurement_fields`.`id` = `measurement_data`.`measurement_id` where `measurement_fields`.`measurement_field_id` in (1, 2, 3))"
In Your Measurement Model Change
public function measurement_data() {
return $this->hasManyThrough(MeasurementField::class, MeasurementField::class, 'measurement_field_id', 'measurement_id');
}
TO
public function measurement_data() {
return $this->hasManyThrough(MeasurementField::class, MeasurementData::class, 'measurement_id', 'measurement_field_id');
}
Refer This
You have some mistakes about the relationships :)
In your Measurement model functions you have changed the the measurement_field and measurement_data.
Try this:
public function measurement_datas() {
return $this->hasMany(MeasurementData::class);
}
public function measurement_fields() {
return $this->hasManyThrough(MeasurementField::class, MeasurementField::class, 'measurement_field_id', 'measurement_id');
}
In your MeasurementField Model functions:
public function measurement_data() {
return $this->belongsTo(MeasurementsData::class, 'measurement_field_id');
}
In your MeasurementData Model functions:
public function measurement() {
return $this->belongsTo(Measurements::class, 'measurement_id');
}
public function measurement_field() {
return $this->hasOne(MeasurementType::class, 'type_id');
}
It is important to use the nameing convention. If it is a one-to-many relation, use plural on the 'many' side, and singular on the 'one' side. Also the name of the realtionship should indicate the name of the class that has been on the relationship, to avoid misunderstanding. Also try to give the correct key names which are presented in the db.
For more information you can find really clear and good documentation about this topic:
https://laravel.com/docs/8.x/eloquent-relationships
I fixed it, in Measurements I had :
public function measurement_data() {
return $this->hasManyThrough(MeasurementField::class, MeasurementField::class, 'measurement_field_id', 'measurement_id');
}
But, this fixed my problem :
public function measurement_fields() {
return $this->hasManyThrough(MeasurementField::class, MeasurementData::class, 'measurement_id', 'id');
}
I am wondering why my 2nd postman request does not work when utilizing variables for graphql api POST request.
The 1st request below works on Postman.
Variables with graphql issue.
query {getById(id: "2"){
id
name
icon
elements {
id name link
elements {
id name link
elements {
id name link
elements {
id name link
}
}
}
}
} }
query {getById($id: String ){
id ($id: id)
name
icon
elements {
id name link
elements {
id name link
elements {
id name link
elements {
id name link
}
}
}
}
}
}
} }
variable
{
"id": "2"
}
Your second postman request is not working because you're not having the node called "2" in the graphQL definition.
A simple breakdown of your request:
query {getById(id: "2"){
Above identifies the item with id 2 from the service.
All below that method are just nodes that you want to retrieve.
Also I think you can just use below:
query {getById($id: String ){
id
name
icon
elements {
id name link
}
}
I use Java library. In exception class there is "localizedMessage" field and "description" field. I don't know why, but "description" (which is java String) is recognized as String! by Kotlin, and when "description" is null, condition description == null returns false.
Example of code:
mvpView?.showToast(it.description?:it.localizedMessage)
or without Elvis:
if (it.description.isNullOrBlank()) {
mvpView?.showToast(it.localizedMessage)
} else {
mvpView?.showToast(it.description)
}
it always tries to show "description", but "evaluate expression" in debug mode returns true on description == null (as expected).
Kotlin version is 1.1.1
The reason was in getter, it returned another string instead of description if description is null.
public String getDescription() {
if (description != null) {
return description;
}
if (UNKNOWN_ERROR.equals(getCode())) {
return String.format("Received error with code %s", getCode());
}
return "Failed with unknown error";
}
I have got four tables in NHibernate
Job
{
DBID { int, primary key }
Name { string }
Media { fk_media (int) }
PublishInfo { fk_publishinfo (int) }
}
Media
{
DBID { int, primary key }
TransmissionID { string }
Series { string }
Title { string }
Description { string }
}
PublishInfo
{
DBID { int, primary key }
Destination { string }
AudioTrack_1 { fk_audiolanguage }
AudioTrack_2 { fk_audiolanguage }
AudioTrack_3 { fk_audiolanguage }
AudioTrack_4 { fk_audiolanguage }
}
AudioLanguage
{
Code { string, primary key }
Description { string }
}
What I want to achive with NHibernate is that it only stores unique records. So if a Media is used multiple times they all point to the same media entry. Same goes for PublishInfo.
A second issue I ran into is that when using the same audiolanguage for audiotrack_3 and 4 for instance it gives a error that is was already used in the session.
Any tips how I would do this properly?
This is a partial anwser to my own question. The reason it wasn't working correctly for the languages when using same lanuage on multiple tracks is because they got send back and forth between a client and server application. The way I solved this is by receiving it back to the server I lookup the proper objects stored in a list on the server and replace them.
I do not think this is the proper solution but it works.