Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show customer name rather than id #32

Open
cyclops24 opened this issue Nov 12, 2015 · 2 comments
Open

show customer name rather than id #32

cyclops24 opened this issue Nov 12, 2015 · 2 comments

Comments

@cyclops24
Copy link

Hi @perak ,
I have a simple question. In the example-invoices how do transform and show customer name in rather than id the DataView??
I talk about this page.
I read json file a lot but I don't understand.
You have this two field in collection definition but how to fill customer.name:

{
                        "name": "customerId",
                        "title": "Customer",
                        "required": true,
                        "input": "select",
                        "lookup_query_name": "customer_list",
                        "lookup_field": "name",
                        "lookup_key": "_id",
                        "show_in_dataview": false,
                        "show_in_read_only_form": false,
                        "exportable": false,

                        "join_collection": "customers",
                        "join_fields": ["name"],
                        "join_container": "customer"
                    },

                    {
                        "name": "customer.name",
                        "title": "Customer",
                        "show_in_insert_form": false,
                        "show_in_update_form": false,
                        "exportable": true
                    },
@perak
Copy link
Owner

perak commented Nov 12, 2015

@cyclops24 customer.name is automatically filled with join described in previous customerId field.

These three lines of code:

"join_collection": "customers",
"join_fields": ["name"],
"join_container": "customer"

join_collection - from which (foreign) collection we want to join data into this collection?
join_fields: - which fields we want to fetch from foreign collection?
join_container: - field name in which data will be fetched from foreign collection, in this case customer - you can name it as you wish.

Now, result from this is that Invoices.find/findOne will return something like this:

{
  ...normal fields from Invoices collection...
  "customer": {
    "name": "Bruce Lee"
  }
}

If you change join rules to this:

{
  "join_collection": "customers",
  "join_fields": ["name", "email"],
  "join_container": "foo"
}

Results will be:

{
  ...normal fields from Invoices collection...
  "foo": {
    "name": "Bruce Lee",
    "email": "[email protected]"
  }
}

This is automatically performed by perak:joins package. Look at docs to see how to perform the same thing manually without kitchen.

@cyclops24
Copy link
Author

Thanks @perak ,
I try to add this feature to my project and after some try find this small bug:
when you enable collection2 support project not compile and crashed with this error message:
Unexpected token
and after remove "use_collection2": true, all things worked well.
If need I can post it as new issue in kitchen-website repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants