-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Sushi models can relate to non-sushi models #98
Sushi models can relate to non-sushi models #98
Conversation
Any update if and when this pr will merged? |
Dang thank you, I was struggling to figure this out when using Sushi in conjunction with Nova. Kept saying no such table but I was staring right at it! |
In the meantime, adding this to my Model provided the workaround: protected function newRelatedInstance($class)
{
return tap(new $class, function ($instance) use ($class) {
if (!$instance->getConnectionName()) {
$instance->setConnection($this->getConnectionResolver()->getDefaultConnection());
parent::newRelatedInstance($class);
}
});
} |
@calebporzio, can this PR be merged? |
This should definitely be merged, very useful! |
Anyone know how Sushi would work with a I tried adding the provided method, but it results in Edit: fixed by adding https://github.com/staudenmeir/eloquent-json-relations |
Is there a reason this is not being merged? |
The solution seems to work even with HasMany relationships. |
hoping this can be merged! |
Hello, I have a model named group with an intermediate table @amadeann @calebporzio @bradenkeith SQLSTATE[HY000]: General error: 1 no such table: group_product (SQL: select "products".*, "group_product"."group_id" as "pivot_group_id", "group_product"."product_id" as "pivot_product_id" from "products" inner join "group_product" on "products"."id" = "group_product"."product_id" where "group_product"."group_id" = 1) When I use newRelatedInstance it returns empty `
} class Group extends Model
// return $this->newRelatedInstance(Product::class)->belongsToMany(Product::class,"group_product",'group_id','product_id','id','okcs_id');
} ` |
Same problem here The
Fixes it for me. :) But would be great if it could be merged or some alternative |
Thanks! |
@calebporzio Could you also create a new release? :) |
In the current version, you cannot have
belongsTo
relationship from a sushi model to a non-sushi one. The reason behind this is that Laravel assumes the related model is in the same database as the one in which the relation is defined unless you explicitly set the connection name on the related model. With this PR, the default connection is used if the name is not specified.The first commit adds the failing test, the second one the fix.