forked from zofe/rapyd-laravel
-
Notifications
You must be signed in to change notification settings - Fork 12
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
extended tags input with belongsToMany relationships #8
Comments
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 ***@***.***> 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: