How filtering field(M2o) child by list in parent with XML - odoo-8

in XML, how i can use domain="[('field2','in',parent.field1)]"
like field1 is Many2one in parent class.
field2 is Many2one in child class. ?

Related

Spring Data Sort in `#Query` annotation on unmapped Property

Is it possible to sort a query on a repository method by specifying an unmapped property? In my particular case I want to use a aggregation result as sort parameter but do not want to map it into the projected class.
interface FooRepository {
#Query("""
select f from Foo f
group by t.id
order by count(t.id) desc
""")
List<Foo> findFooSorted();
}

schema design union vs flat properties

when I have a parent Object type that needs to point to a child Object type but that child Object's type can be of several types and only one can be chosen and populated. I see 2 options I can do with regard to graphql schema design.
option 1 - use union
type child1{......}
type child2{......}
union chooseOne = child1 | child2
type parent{
ref: chooseOne
}
option 2 use multiple props and have only one with data - the rest with nulls
type child1{......}
type child2{......}
type parent{
ref1: child1
ref2: child2
}
is there a 3rd option I am not thinking of? I am not that please with either. I feel like I am missing something... can anyone please comment? thanks! (edited)
am I missing a third possible option?
using an array
type Meeting{
.........(some properties)
recurrences : [Recurrence]
}
union Recurrence = Once | WeeklyRecurrence | MonthlyRecurrence | DailyRecurrence
Of course it looks like a relation ... and it is ... and gives you more possibilities.
all of them can have validFrom and validUntil times - you can filter out all historical entries automatically without manual disabling/removing
you can have AND combinations instead OR, for example 'every working day at 10.00, additionally at 15.00 on fridays'
you can process recurrence entries separately f.e. for notifications (having meeting id just fetch attendees from another relation)
But in fact maybe you don't need separate recurrence types at all, only one field/property (enumerated types) to know which fields are required for render/forms/resolver/mutations etc.
... all of them can use the same DB table, the same record structures in both cases (types mapped to enumed type field).
Update
I prefer 2nd option:
it's more readable/debuggable
it's easier to handle - if(ref1)...<Ref1Component data={ref1}/> ... passing union data object you don't have info about type!
unions sometimes leads to troubles like this

Laravel - How to extract one field for items in a model to an array?

I have a table that has a one-to-many relationship with another table.
Call them tables parent and child
child has a field called field1
I am trying to get an array of all field1 values.
In the parent Model, I have this function that gets me all children of parent
public function children()
{
return $this->hasMany(Child::class);
}
Now, in the parent model, I also want to get all field1 values.
I can get all the children like so:
$children = $this->children->all();
But I just can't figure out how to then index into this to get all the field1 values.
Maybe it is better to just use $this->children in which case it is a Collection and then use some sort of Collection method to extract field1?
I tried
$this->children->only(['field1'])
but that returned nothing, even though field1 certain exists.
Ideas?
Thanks!
You can use pluck method of collecion to get an array of field1 values:
$parent->child->pluck('field1');
Or better, you can use pluck method of query builder (see section Retrieving A List Of Column Values), being even more efficient, with same result:
$parent->child()->pluck('field1');
map() is the function you are looking.
$children = $this->children->all()->map(function($children) {
return $children->field1;
});
A shorter version using Higher Order Message.
$children = $this->children->all()->map->field1;

Spring jdbc repository many-to-many conjunction table column names

I can't find where to define custom column name for conjunction table in case of many-to-many relationship in spring-data-jdbc.
I extended aggregate example from https://github.com/spring-projects/spring-data-examples in my fork: https://github.com/konstiak/spring-data-examples/commit/2a901bb4d81c35406da393b1368109136ae21f5f.
If the conjuction table has columns [color, lego_set] it works out of box. But I'd like to have custom names for these columns [color_id, lego_set_id]. It's clear for 'color_id'. I can define it by #Column annotation in ColorRef entity. But how can I define that column for LegoSet.id will be stored in 'lego_set_id'?
RESOLVED
I just had to define #Column(value = "lego_set_id") on colors field in LegoSet entity.
Defining #Column(value = "lego_set_id") on colors field in LegoSet entity resolved the problem.

Get multiple selected values from list in arrraylist on select in Spring MVC

I have a bean class named AnnouncementDetails having attributes
Now on submit i want to get the values of the selected users in selectedUsers Arraylist. Any idea how to do that? ..............................................
Change datatype to String array and then convert to arraylist by Arrays.asList(selectedUsers).
String [] selectedUsers

Resources