Trouble accessing `has_many` relationships in a smart view

Hi :wave:t3:

Could you please tell me how we can access has_many relationships in a smart view. I have tried the below code snippet, but it’s not working.

{{#each @records as |record|}}
<div class="block">
  <p>{{record.forest-name}}</p>
  <hr class="solid">
  {{#each record.forest-campaigns as |campaign|}}
  <p><strong> Campaign1: </strong> {{campaign.forest-name}} </p>
  {{/each}}
  <p><strong> Flows: </strong> Text </p>
</div>
{{/each}}

Expected behavior

Please describe here the behavior you are expecting.

Actual behavior

Failure Logs

NameError (uninitialized constant ForestLiana::UserSpace::ActionController):
  
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:298:in `const_get'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:298:in `block in constantize'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `each'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `inject'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `constantize'
activesupport (5.2.4.2) lib/active_support/core_ext/string/inflections.rb:68:in `constantize'
forest_liana (5.4.3) app/controllers/forest_liana/router.rb:16:in `call'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
railties (5.2.4.2) lib/rails/engine.rb:524:in `call'
railties (5.2.4.2) lib/rails/railtie.rb:190:in `public_send'
railties (5.2.4.2) lib/rails/railtie.rb:190:in `method_missing'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
bullet (6.1.0) lib/bullet/rack.rb:12:in `call'
exception_notification (4.4.0) lib/exception_notification/rack.rb:36:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.0.9) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.9) lib/rack/etag.rb:25:in `call'
rack (2.0.9) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.9) lib/rack/head.rb:12:in `call'
actionpack (5.2.4.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.9) lib/rack/session/abstract/id.rb:259:in `context'
rack (2.0.9) lib/rack/session/abstract/id.rb:253:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.4.2) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.4.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.4.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.4.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.4.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.4.2) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.0) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.9) lib/rack/method_override.rb:22:in `call'
rack (2.0.9) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.4.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
rack-rewrite (1.5.1) lib/rack/rewrite.rb:24:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.9) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
railties (5.2.4.2) lib/rails/engine.rb:524:in `call'
thin (1.7.2) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.7.2) lib/thin/connection.rb:84:in `catch'
thin (1.7.2) lib/thin/connection.rb:84:in `pre_process'
thin (1.7.2) lib/thin/connection.rb:53:in `process'
thin (1.7.2) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run_machine'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run'
thin (1.7.2) lib/thin/backends/base.rb:73:in `start'
thin (1.7.2) lib/thin/server.rb:162:in `start'
rack (2.0.9) lib/rack/handler/thin.rb:22:in `run'
rack (2.0.9) lib/rack/server.rb:297:in `start'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:53:in `start'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:147:in `block in perform'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:142:in `tap'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:142:in `perform'
thor (1.0.1) lib/thor/command.rb:27:in `run'
thor (1.0.1) lib/thor/invocation.rb:127:in `invoke_command'
thor (1.0.1) lib/thor.rb:392:in `dispatch'
railties (5.2.4.2) lib/rails/command/base.rb:69:in `perform'
railties (5.2.4.2) lib/rails/command.rb:46:in `invoke'
railties (5.2.4.2) lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<top (required)>'
spring (2.1.0) lib/spring/client/rails.rb:28:in `load'
spring (2.1.0) lib/spring/client/rails.rb:28:in `call'
spring (2.1.0) lib/spring/client/command.rb:7:in `call'
spring (2.1.0) lib/spring/client.rb:30:in `run'
spring (2.1.0) bin/spring:49:in `<top (required)>'
spring (2.1.0) lib/spring/binstub.rb:11:in `load'
spring (2.1.0) lib/spring/binstub.rb:11:in `<top (required)>'
bin/spring:13:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Started GET "/forest/Action/count?fields%5BAction%5D=ability%2Ccreated_at%2Cid%2Cname%2Cupdated_at&searchExtended=0&timezone=Asia%2FKolkata" for ::1 at 2021-02-16 20:29:53 +0530
  
NameError (uninitialized constant ForestLiana::UserSpace::ActionController):
  
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:298:in `const_get'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:298:in `block in constantize'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `each'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `inject'
activesupport (5.2.4.2) lib/active_support/inflector/methods.rb:281:in `constantize'
activesupport (5.2.4.2) lib/active_support/core_ext/string/inflections.rb:68:in `constantize'
forest_liana (5.4.3) app/controllers/forest_liana/router.rb:16:in `call'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
railties (5.2.4.2) lib/rails/engine.rb:524:in `call'
railties (5.2.4.2) lib/rails/railtie.rb:190:in `public_send'
railties (5.2.4.2) lib/rails/railtie.rb:190:in `method_missing'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (5.2.4.2) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.4.2) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.4.2) lib/action_dispatch/routing/route_set.rb:840:in `call'
bullet (6.1.0) lib/bullet/rack.rb:12:in `call'
exception_notification (4.4.0) lib/exception_notification/rack.rb:36:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.0.9) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.9) lib/rack/etag.rb:25:in `call'
rack (2.0.9) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.9) lib/rack/head.rb:12:in `call'
actionpack (5.2.4.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.9) lib/rack/session/abstract/id.rb:259:in `context'
rack (2.0.9) lib/rack/session/abstract/id.rb:253:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.4.2) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.4.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.4.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.4.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.4.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.4.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.4.2) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.0) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.9) lib/rack/method_override.rb:22:in `call'
rack (2.0.9) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.4.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
rack-rewrite (1.5.1) lib/rack/rewrite.rb:24:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.4.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.9) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
railties (5.2.4.2) lib/rails/engine.rb:524:in `call'
thin (1.7.2) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.7.2) lib/thin/connection.rb:84:in `catch'
thin (1.7.2) lib/thin/connection.rb:84:in `pre_process'
thin (1.7.2) lib/thin/connection.rb:53:in `process'
thin (1.7.2) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run_machine'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run'
thin (1.7.2) lib/thin/backends/base.rb:73:in `start'
thin (1.7.2) lib/thin/server.rb:162:in `start'
rack (2.0.9) lib/rack/handler/thin.rb:22:in `run'
rack (2.0.9) lib/rack/server.rb:297:in `start'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:53:in `start'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:147:in `block in perform'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:142:in `tap'
railties (5.2.4.2) lib/rails/commands/server/server_command.rb:142:in `perform'
thor (1.0.1) lib/thor/command.rb:27:in `run'
thor (1.0.1) lib/thor/invocation.rb:127:in `invoke_command'
thor (1.0.1) lib/thor.rb:392:in `dispatch'
railties (5.2.4.2) lib/rails/command/base.rb:69:in `perform'
railties (5.2.4.2) lib/rails/command.rb:46:in `invoke'
railties (5.2.4.2) lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<top (required)>'
spring (2.1.0) lib/spring/client/rails.rb:28:in `load'
spring (2.1.0) lib/spring/client/rails.rb:28:in `call'
spring (2.1.0) lib/spring/client/command.rb:7:in `call'
spring (2.1.0) lib/spring/client.rb:30:in `run'
spring (2.1.0) bin/spring:49:in `<top (required)>'
spring (2.1.0) lib/spring/binstub.rb:11:in `load'
spring (2.1.0) lib/spring/binstub.rb:11:in `<top (required)>'
bin/spring:13:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Context

Please provide any relevant information about your setup.

  • Package Version: Forest Liana v5.4.3
  • Project Name: gemDatabyte-server

Hi @ziad,

Do you have any errors in your browser console?

I did a quick test on my end with this code (@records = Customers, has many Orders) and the following code seems to work fine.

    {{#each @records as |record|}}
    <div class="block">
      <p>{{record.forest-id}} - {{record.forest-email}}</p>
      <hr class="solid">
      {{#each record.forest-order as |order|}} <!-- Notice that I removed the final `s` -->
        <p><strong> Status: </strong> {{order.forest-status}} </p>
      {{/each}}
    </div>
    {{/each}}

Still, I find strange that you are getting an error on the agent side. Do you also see this issue while in the table view, and do you have any error in your browser console/network tabs?

Thanks in advance.

Hi @jeffladiray @ziad

I dont see any error on browser console ,but has_many records are not getting loaded.

Let me know if you need anything from my end.

Thanks,
Rajesh

Hi @Rajesh_Kumar,

Sorry for the delayed response, I had hard time figuring this out.

For a bit more context, I was testing this using a lumber-based project (Using nodejs), which does not have the exact same behavior, that’s why I was not able to reproduce.

Correct me if I’m wrong, but the frontend does not ask specifically for the relationship field in the getAll/ tableview request (The API call made by the frontend does not ask for the campaigns field in your case), thus the response does not contain the relationship links associated with your records, which are needed to display the data.

I’m opening a ticket related to this, and we will update this thread once fixed :raised_hands:

Thanks for your patience.

1 Like

Hi @jeffladiray ,

Do you have any update on it ?

Hello @Rajesh_Kumar

The ticket was open for your issue, but it was not yet solved.

We will update this thread once we have a solution for you.

Thank you for your patience :blush: