Building Relations between ObjecTypes in Typgraphql and Prisma - apollo

I am trying to create a relation between 2 ObjecTypes in Typgraphql with Apollo. This is my error:
As you can see in my category section I get null. This should be an item, because I already see it in my prisma ORM
#FieldResolver(() => Category)
async categories(#Root() parent: Product, #Ctx() ctx:Context): Promise<Category[]> {
return await ctx.prisma.category.findUnique({
where: {id: parent.id}
}).categories()!
}
I created a FieldResolver that returns the category when running the product's id. However, when I run categories at the end I get the following error: Property 'categories' does not exist on type 'Prisma__CategoryClient<Category | null>'.
I don't why I am getting this issue. Any information would be greatly appreciated.

Related

`op_name` parameter for `graphene_django`

The django graphene documentation shows a test example like this:
class MyFancyTestCase(GraphQLTestCase):
def test_some_query(self):
response = self.query(
'''
query {
myModel {
id
name
}
}
''',
op_name='myModel'
)
content = json.loads(response.content)
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
# Add some more asserts if you like
...
They don't have any API documentation for what op_name is, and what we should set it as. I tried to set it to my query name, but get the error:
[{'message': 'Unknown operation named "myQuery".'}]
Operation name is only needed when there are multiple operations in the query string. You only have one operation so the default (None) is fine.
https://docs.graphene-python.org/en/latest/execution/execute/#operation-name
As per my comment:
If the query is a mutation or named query, you must supply the op_name. For annon queries ("{ ... }"), should be None (default)
I am not sure how to create a "named query" with django graphene, but apparently my query is NOT a named query. Leaving op_name as None got my query to work via my unit test.

Update One2many Fields in the view

I have a model A which has an one2mny relation with another model B and the later has also an one2many relation with a model C.
I want to use self.update to update the one2many relation in the model A in and onchange method so accordingly update the one2many relation in the model B.
I have managed to update the first one but the second one is not updated here what i have done :
temp.append((0,0,{
'periode':periode,
'ca':ca,
'loc':loc,
'line_rs':line_rsc,
}))
self.update({
'periode_line':temp
})
where line_rsc is a list that should be used to update the second
one2many relation
Thanks
secod pic (secod one2many relation):
i tried this using the new api and it seems to be working just fine:
# this will add the new record to existing records
#api.onchange(..)
def .....(self):
self.update(
{'o2m_1_field': [{
'o2m_1_field_name': 'value',
'o2m_1_field_o2m_2_name': [{'o2m_2_field': 'value'}]
}]
}
)
this logic works fine in new api.
or you can do it like this
# this will add the new record to existing records
self.o2m_1_field += self.env['o2m.1.model.name'].new({
'o2m_1_field_name': 'value',
'o2m_1_field_o2m_2_name': [{'o2m_2_field': 'value'}]
})
if this is not working for you and giving you bad query error then you need to
use the latest version of odoo 8 because a lot has been changing you can even
do onchange on a o2m_field now ...

Odoo error: return self.models[model_name] KeyError: 'res_groups_users_rel'

I need to make UI many2one dopdown list where I can identify users which depend to Manager group role.
Now I have dropdown field:
test = fields.Many2one('res.groups', 'Purchase request type', default=_get_users, track_visibility='onchange')
And I tried to write a function which can identify all users which depend to manager group role.
def _get_users(self):
pickings = self.env['res_groups_users_rel'].search([('gid','=',61)])
pickings_available = []
for picking in pickings:
pickings_available.append(picking)
return pickings_available
And I got an error:
return self.models[model_name]
KeyError: 'res_groups_users_rel'
I don't know how can I change this function and get value from amy2many relation.
I changed my function to:
def _get_users(self):
pickings = self.env['res.groups'].browse(61).users
pickings_available = []
for picking in pickings:
pickings_available.append(picking)
return pickings_available
and field:
test = fields.Many2one('res.users', 'Some text', default=_get_users, track_visibility='onchange')
I logged function _get_users and get values: [res.users(9,), res.users(65,)]
But I still can't get these values on my test field dropdown. What I am doing wrong?
If you are trying to get all users that belong to a group, why not do the following:
self.env['res_groups'].browse(61).users
On a side note, you might get an error, trying to assign a list as default value to a Many2one field.
Also you seem to be assigning users belonging to a group to a field that is specified to store reference to groups.
If you need to have a field to select a user that belongs to group with id 61, you can do the following:
test = fields.Many2one('res.users', 'Some description', domain="[('groups_id', 'in', [61])]")

Does store.find() method use different inflection rules from ember-inflector?

I'm building a simple Ember application using Ember v1.0.0 and Ember-Data v1.0.0-beta.3. I have a model called 'Categoria'
categoria.coffee:
App.Categoria = DS.Model.extend
nombre: DS.attr 'string'
simplified: DS.attr 'boolean'
candidatos: DS.hasMany 'candidato'
When I try to find a 'Categoria' by it's id, I always get error message:
Assertion failed: No model was found for 'categorium'
categoria_route.coffee:
App.CategoriaRoute = Em.Route.extend(
model: (params)->
#store.find('categoria', params.categoria_id)
)
App.CategoriaIndexRoute = Em.Route.extend(
model: ->
categoria = #modelFor('categoria')
categoria.reload() if categoria.get('simplified')
categoria
)
I've specified the inflections rules, due the spanish-named model.
store.coffee:
Ember.Inflector.inflector.irregular('categoria', 'categorias')
Ember.Inflector.inflector.rules.irregularInverse['categorias'] = 'categoria'
App.ApplicationAdapter = DS.ActiveModelAdapter()
App.ApplicationSerializer = DS.ActiveModelSerializer.extend()
I'm wondering if the find method of the Store uses a different set of inflections rules? or is there any other place where I should declare the inflection rules for this model?
It worths to mention that requests to the server for this model are made correctly (to the right URL) and they're responded well formed.
I've tried to use different syntax for the store.find method as mentioned in the Ember Guides#Method Find (http://emberjs.com/api/data/classes/DS.Store.html#method_find) but the error is the same.
The problem is when it tries to singularize the json response, it attempts to singularize categoria and it returns categorium, your pluralization was working fine.
var iff = Ember.Inflector.inflector;
iff.irregular('categoria', 'categorias');
// this adds a test for when it finds categoria and you are trying to singularize, return categoria
iff.singular(/categoria/, 'categoria');
http://emberjs.jsbin.com/ICeGuzuX/3/edit

symfony 1.4 and propel - foreign constraints fails saved relation

I am working in a Symfony 1.4 project with Propel 1.4.2.
I have 2 related tables. workshop and trainers which is a many to many relation mapped by a join table (workshop_trainers) which contains the workshop_id and the trainer_id).
In my Workshop Form I have a select box for adding the trainers to the workshop. The problem is when the workshop is new (Create) I get an error:
Cannot add or update a child row: a foreign key constraint fails
This happens because, when saving the workshop_trainers relation the workshop_id field is null. IsnĀ“t Propel intelligent enough to know that there is a relation between the tables and save the base object first? What I am doing wrong?
My trainer list widget.
$this->widgetSchema['workshop_trainer_list'] = new sfWidgetFormChoice(array(
'choices' => $trainers,
'multiple' => true,
));
Thanks for your help.
This is not fixing the problem but that's the easiest practical solution to this problem:
In the form, simply deactivate the workshop_trainer_list field if the object is a new one (doesn't have an ID yet).
Something like:
if ($this->getObject()->isNew())
{
$this->offsetUnset('workshop_trainer_list'); // not sure of that method name
}
A better solution is to update the doSave method to have the ID first, something like this:
protected function doSave($con = null)
{
$isNew = $this->getObject()->isNew();
if (null === $con)
{
$con = $this->getConnection();
}
// retrieve the value of workshop_trainer_list here and remove it from the form
$trainers = ...
$this->offsetUnset('workshop_trainer_list');
// save without it
parent::doSave($con);
// add it back
$this->getObject()->set...
// save
$this->getObject()->save($con);
}