Dot Notation and type navigation

#1

Hi C3,

How does one find resources for using the dot notation and navigate the type system.
Can someone provide the fundamentals so I can join types and filter on id’s singular/multiple/all

thanks

0 Likes

#2

What do you mean by join types?
If you want to filter on ids, here is an example:

var ids = [ ... ]
var intersects = Filter.intersects('id', ids);
var instances = SampleType.fetch({filter: intersects})

Hope that helps.

0 Likes

#3

So all of the types in our data model represent different parts of an oil gas well.

so
I say:
c3Grid(TubingComponent.fetch({limit:100, inlcude: “tubing.slotConnections.to.parent”})

How do I learn the syntax to pull together multiple types.
in some cases I have seen examples where its .to and other .from.

0 Likes

#4

I see what do you mean, to learn what you can use, you actually have to look to the fields inside your type.
Ex:

TypeA {
  typeB: TypeB
}
TypeB {
  typeC: TypeC
}
TypeC {
 somefield: ...
}

Then:

  1. from TypeA you can have an expression like typeB.typeC.somefield
  2. from TypeB you can have an expression like typeC.somefield
  3. from TypeC you can have an expression like somefield
0 Likes

#5

OK EXAMPLE:
I have a head type and all other types contain information relating back to that type.

I want type1.allFields + type2.allFields …typen.allFields

and they belong to type1 unique id. generic example would be type1 holds something like employeeID so lets start by just fetching the data that belongs to a single employee id across all types.

0 Likes

#6

I’m not fully understanding, but you may be thinking about foreign key relations? E.g

type Business {
  employees: [Person] (worksFor)
}

type Person {
  worksFor: Business
}

Then on a business with id “2” You could call:

Business.fetch({filter: "id == '2'", include: "employees"})

The field “employees” is not stored on the Business table in this case, but is calculated on the fly by fetching all Person objects who have Business with id=2 in the ‘worksFor’ field

0 Likes

#7

ok lets simplify.

c3.grid(c3.TubingComponent.fetch(limit = 999))
c3.grid(c3.Tubing.fetch(limit=999999))
c3.grid(c3.TubingSlotConnection.fetch(limit=999999))
c3.grid(c3.TubingSlot.fetch(limit=999999))
etc
back to well.

I want all fields in those types for a single well which is the top of the hierarchy.

0 Likes

#8

I’m finding it a bit hard to understand your question… can you give your example types similar to how i did in my above example?

include does not ‘filter down’ what you fetch, its more like in sql when you say SELECT ID, NAME FROM TABLE, the c3 version of that is Table.fetch({include: id, name})

0 Likes

#9

OK so lets say, e.g. you have

type Well {
  tubings: [Tubing] (well)
}
type Tubing {
  well: Well
  components: [TubingComponent] (tubing)
  number int
}
type TubingComponent {
  tubing: Tubing
  otherField: string
  finalField: int
}

and you want to fetch all fields on all types for children ofa singel well. You could write:

Well.fetch({include: "{tubings: [number, {components: [otherField, finalField]}]}"})

I recommend you to start with c3ShowType(Well), and on this type to check the api called ‘fetch’ for documentation. That ‘fetch’ api takes a FetchSpec (which you can see by c3ShowType(FetchSpec) or clicking on that type in the Well.fetch doc) as its input, and on that FetchSpec type there is a field called ‘include’ with rather detailed doc which i will copy here for reference (THE DOCS IN THE ENV SUPERCEDE ANYTHIGN I WRITE HERE)

include: string
Specifies which fields to bring back values for in the returned Obj instances. Include specifications are logically a list of field paths. The following examples illustrate the supported ways to specify them:

  1. Simple list of fields - “[field1, field2, field3]”
  2. List of fields involving references and non-reference fields - “[refField1.name, refField1.refField2.name]”
  3. Same as above with Obj notation - “[{refField1: [name, {refField2: [name]}]}]”
  4. Return all fields in obj - Either not specified or “[this]” Note that for external references, only the ids are returned unless an explicit include indicates that data from the reference should be returned (see below). Also, fkey fields (e.g. fields defined like arry: SomeType(fkeyField)) are also only brought back if specifically included.
  5. Using dot query to filter arry/mapp results - “[refArry.(name == ‘foo’)]” or “[{refArry}.(name == ‘foo’)]”
1 Like

#10

A note on limits…
The fetch() api takes a “limit” parameter, which you can see in the same doc. This parameter defaults to 2000. This limit applies to the type on which the api is called, so e.g. if you call

Well.fetch({limit: 10})

You will get back AT MOST 10 wells… this limit does not apply to objects in the include spec, so e.g. you cannot limit the number of child objects which are returned, if you do Well.fetch({limit: 1, include: children}) on a well with 1million children… the system will try to fetch all 1million children and probably choke the db.

Another good way to choke the DB is to write a fetch with limit: -1, which i encourage you to NEVER DO but to check the doc to see what it does.

0 Likes