You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling with_[relation] method selecting the object without the primary key field in the select will fail as seen in this example:
Example of failure
This will fail:
packages.with_offer(&.select("name")).each ...
giving this error:
[WARN] You're trying to access to the column `id` but it is not initialized.
Here some tips:
- Ensure that the column `id` exists in your table
- If the model comes from a collection query, there was maybe a filtering
on your `select` clause, and you forgot to declare the column `id`
- In the case of unpersisted models, please initialize by calling `id=`
first
- For validator, try `ensure_than` method, or use `id_column.defined?` to
avoid your validation code.
- Are you calling `id_column.revert` somewhere before?
- If your model comes from JSON, please ensure the JSON source defines the
column. Usage of `strict` mode will trigger exception on JSON loading.
You may want to check the manual:
https://github.com/anykeyh/clear/tree/master/manual/model/Definition.md
https://github.com/anykeyh/clear/tree/master/manual/model/Lifecycle.md
You may also have encountered a bug.
Feel free to submit an issue:
https://github.com/anykeyh/clear/issues/new
Reason
The cache engine use the primary key to encache the relations and avoid N+1. But the primary key is here not accessible.
Fix
Currently a fix seems difficult. It might need to force the selection of the primary key field, but then can lead to difficult situations (e.g. ambigous columns selection).
However, improving the error message might be a first step forward.
The text was updated successfully, but these errors were encountered:
Issue
Calling
with_[relation]
method selecting the object without theprimary key
field in theselect
will fail as seen in this example:Example of failure
This will fail:
giving this error:
Reason
The cache engine use the primary key to encache the relations and avoid N+1. But the primary key is here not accessible.
Fix
Currently a fix seems difficult. It might need to force the selection of the primary key field, but then can lead to difficult situations (e.g. ambigous columns selection).
However, improving the error message might be a first step forward.
The text was updated successfully, but these errors were encountered: