Open jbajou opened 8 years ago
Any idea anybody ? Still stuck there...
did you still need help ?
Hi
We got that sorted out: I'll try to post some snippets asap
On Nov 26, 2016, at 11:43 AM, Serverfire notifications@github.com wrote:
did you still need help ?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Please send a pull request so we can add that filed type
@jbajou still waiting
Hello,
I extended the Tags field because I needed it not to request data from database. This works just fine. I'm trying now to save the entered tags to database.
I have a blog_posts table and a blog_post_tags. A pivot table blog_post_blog_post_tag has been created containing the id of the post and the id of the tag.
The BlogPost model has a method as follow:
public function blogPostTag() { return $this->belongsToMany('App\BlogPostTag', 'blog_post_blog_post_tag', 'blog_post_id', 'blog_post_tag_id'); }
The BlogPostTag model has a method as follow:
public function blogPost() { return $this->belongsToMany('App\BlogPost', 'blog_post_blog_post_tag', 'blog_post_tag_id', 'blog_post_id'); }
When I try to save data, the content of the input is sent to the query, so Laravel tries to save both the blog_post_id and the content of the input in the pivot table. Here is the error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
dbname.
blog_post_blog_post_tag, CONSTRAINT
blog_post_blog_post_tag_blog_post_tag_id_foreignFOREIGN KEY (
blog_post_tag_id) REFERENCES
blog_post_tags(
id)) (SQL: insert into
blog_post_blog_post_tag(
blog_post_id,
blog_post_tag_id) values (1, super,test))
What can I do so it works as expected, i.e. add a line in pivot table for each tag, and save the tag in its table if needed. I think I miss something in my extended TagField... Here is the code so far:
`class TagsField extends \Zofe\Rapyd\DataForm\Field\Field {
acp;
}`
Thanks in advance for your help